-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
openmrs: add a generic http request #923
Merged
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c597d0c
feat/ implement http request
hunterachieng beae533
fix: update request with new arguments
hunterachieng 3cdf607
fix: throw error for empty baseUrls and share typedefs
hunterachieng 8c07d2d
fix: add default baseUrl
hunterachieng 12b37a2
fix: update docs
hunterachieng 7a586a4
remove import docs
hunterachieng 386302b
add typedef object in http
hunterachieng d0c39f7
fix: add tests
hunterachieng 5d6839e
add changeset
hunterachieng 179c1a6
fix baseUrl and changeset
hunterachieng 106142b
version: openmrs@4.2.0
hunterachieng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { expandReferences } from '@openfn/language-common/util'; | ||
import * as util from './Utils'; | ||
|
||
/** | ||
* Options object | ||
* @typedef {Object} OpenMRSOptions | ||
josephjclark marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @property {object} query - An object of query parameters to be encoded into the URL | ||
* @property {object} headers - An object of all request headers | ||
* @property {object} body - The request body (as JSON) | ||
* @property {string} baseUrl - The base url for the request | ||
hunterachieng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @property {string} [parseAs='json'] - The response format to parse (e.g., 'json', 'text', or 'stream') | ||
*/ | ||
|
||
/** | ||
* Make a HTTP request to any OpenMRS endpoint | ||
* @example | ||
* request("GET", | ||
* "/ws/rest/v1/patient/d3f7e1a8-0114-4de6-914b-41a11fc8a1a8", { | ||
* query:{ | ||
* limit: 1, | ||
* offset: 20 | ||
* }, | ||
* baseUrl: "http://msf-ocg-openmrs3-dev.westeurope.cloudapp.azure.com/openmrs" | ||
hunterachieng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* }); | ||
* @function | ||
* @public | ||
* @param {string} method - HTTP method to use | ||
* @param {string} path - Path to resource | ||
* @param {OpenMRSOptions} [options={}] - An object containing either query, headers, and body for the request | ||
hunterachieng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @returns {Operation} | ||
*/ | ||
export function request(method, path, options = {}, callback = s => s) { | ||
return async state => { | ||
const [resolvedMethod, resolvedPath, resolvedOptions = {}] = | ||
expandReferences(state, method, path, options); | ||
|
||
const response = await util.request( | ||
state, | ||
resolvedMethod, | ||
resolvedPath, | ||
resolvedOptions | ||
); | ||
|
||
return util.prepareNextState(state, response, callback); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ export default Adaptor; | |
|
||
export * from './Adaptor'; | ||
export * as fhir from './fhir'; | ||
export * as http from './http' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably remove this if we're not keeping it