Skip to content

Commit

Permalink
feat/ implement http request
Browse files Browse the repository at this point in the history
Signed-off-by: Hunter Achieng <[email protected]>
  • Loading branch information
hunterachieng committed Jan 17, 2025
1 parent 5403fcc commit c597d0c
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/openmrs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"configuration-schema.json"
],
"dependencies": {
"@openfn/language-common": "workspace:*"
"@openfn/language-common": "workspace:*",
"@openfn/language-http": "workspace:*"
},
"devDependencies": {
"@openfn/simple-ast": "^0.4.1",
Expand Down
43 changes: 43 additions & 0 deletions packages/openmrs/src/http.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

import { expandReferences } from '@openfn/language-common/util';
import * as http from '@openfn/language-http'

/**
* State object
* @typedef {Object} OpenMRSOptions
* @property {object} query - An object of query parameters to be encoded into the URL
* @property {object} header - An object of all request headers
* @property {object} body - The request body (as JSON)
*/



/**
* Make a HTTP request to any OpenMRS endpoint
* @example
* request("GET","http://msf-ocg-openmrs3-dev.westeurope.cloudapp.azure.com/openmrs/ws/rest/v1/patient/d3f7e1a8-0114-4de6-914b-41a11fc8a1a8", {
* {query: {
* q: "Patient",
* limit: 1,
* }}
* });
* @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
* @returns {Operation}
*/
export function request(method, path, options = {}, callback = s => s ) {
return async state => {
const [resolvedMethod, resolvedPath, resolvedOptions = {}] = expandReferences(
state,
method,
path,
options
);

await http.request(resolvedMethod, resolvedPath,resolvedOptions, callback)

};
}
1 change: 1 addition & 0 deletions packages/openmrs/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export default Adaptor;

export * from './Adaptor';
export * as fhir from './fhir';
export * as http from './http'
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c597d0c

Please sign in to comment.