-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #923 from OpenFn/feature/openmrs-rework-889
openmrs: add a generic http request
- Loading branch information
Showing
7 changed files
with
216 additions
and
73 deletions.
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
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,44 @@ | ||
import { expandReferences } from '@openfn/language-common/util'; | ||
import * as util from './Utils'; | ||
|
||
/** | ||
* Options object | ||
* @typedef {Object} OpenMRSOptions | ||
* @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} [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 | ||
* }, | ||
* }); | ||
* @function | ||
* @public | ||
* @param {string} method - HTTP method to use | ||
* @param {string} path - Path to resource | ||
* @param {OpenMRSOptions} [options={}] - An object containing query, headers, and body for the request | ||
* @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.