/** * State object * @typedef {Object} HttpState * @private * @property data - The response body (as JSON) * @property response - The HTTP response from the OpenMRS server (excluding the body) * @property references - An array containing all previous data objects * @private */ /** * Options object * @typedef {Object} HTTPRequestOptions * @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} data - The request body (as JSON) * @property {object|boolean} errors - Pass `false` to not throw on errors. Pass a map of errorCodes: error messages, ie, `{ 404: 'Resource not found' }`, or `false` to suppress errors for a specific code. * @property {string} [parseAs='json'] - The response format to parse (e.g., 'json', 'text', or 'stream') * @property {object} tls - TLS/SSL options for this request. Overrides `configuration.tls`. See https://nodejs.org/api/tls.html#tlscreatesecurecontextoptions */ /** * Make a HTTP request to any OpenMRS endpoint * @example GET request with a query parameters * http.request("GET", * "/ws/rest/v1/patient/d3f7e1a8-0114-4de6-914b-41a11fc8a1a8", { * query:{ * limit: 1, * startIndex: 20 * }, * }); * @example PUT request with a payload * http.request("PUT", * "/ws/rest/v1/patient/d3f7e1a8-0114-4de6-914b-41a11fc8a1a8", * { data: $.resource }, * ); * @function * @public * @param {string} method - HTTP method to use * @param {string} path - Path to resource * @param {HTTPRequestOptions} [options={}] - An object containing query, headers, and body for the request * @state {HttpState} * @returns {Operation} */ export function request(method: string, path: string, options?: HTTPRequestOptions): Operation; /** * Make a GET request to any OpenMRS endpoint. * Unlike the main `get()`, this does not append anything to the path you provide. * @public * @function * @example GET a resource with a query * http.get( * "/ws/rest/v1/patient", * { * query: { * limit: 1 * } * } * ) * @example Don't throw if OpenMRS returns a 404 error code * http.get( * "/ws/rest/v1/patient", * { * errors: { 404: false } * } * ) * @param {string} path - path to resource * @param {HTTPRequestOptions} [options={}] - An object containing query params and headers for the request * @state {HttpState} * @returns {operation} */ export function get(path: string, options?: HTTPRequestOptions): operation; /** * Make a POST request to an OpenMRS endpoint * @public * @function * @example Post with a JSON payload * http.post( * "/ws/rest/v1/patient", * { * "person": { * "gender":"M", * "age":47, * "birthdate":"1970-01-01T00:00:00.000+0100", * "names":[ * { * "givenName":"Jon", * "familyName":"Snow" * } * ], * } * } * ) * @param {string} path - path to resource * @param {any} data - the payload * @param {HTTPRequestOptions} [options={}] - An object containing query params and headers for the request * @state {HttpState} * @returns {operation} */ export function post(path: string, data: any, options?: HTTPRequestOptions): operation; /** * Make a PUT request to an OpenMRS endpoint * @public * @function * @example Put with a JSON payload * http.put( * "/ws/rest/v1/patient", * { * "person": { * "gender":"M", * "age":47, * "birthdate":"1970-01-01T00:00:00.000+0100", * "names":[ * { * "givenName":"Jon", * "familyName":"Snow" * } * ], * } * } * ) * @param {string} path - path to resource * @param {any} data - the payload * @param {HTTPRequestOptions} [options={}] - An object containing query params and headers for the request * @state {HttpState} * @returns {operation} */ export function put(path: string, data: any, options?: HTTPRequestOptions): operation; /** * State object */ export type HttpState = any; /** * Options object */ export type HTTPRequestOptions = { /** * - An object of query parameters to be encoded into the URL */ query: object; /** * - An object of all request headers */ headers: object; /** * - The request body (as JSON) */ data: object; /** * - Pass `false` to not throw on errors. Pass a map of errorCodes: error messages, ie, `{ 404: 'Resource not found' }`, or `false` to suppress errors for a specific code. */ errors: object | boolean; /** * - The response format to parse (e.g., 'json', 'text', or 'stream') */ parseAs?: string; /** * - TLS/SSL options for this request. Overrides `configuration.tls`. See https://nodejs.org/api/tls.html#tlscreatesecurecontextoptions */ tls: object; }; /** * Make a DELETE request to an OpenMRS endpoint * @alias delete * @public * @function * @example Delete a resource * http.delete( * "/ws/rest/v1/patient/abc/" * ) * @param {string} path - path to resource * @param {HTTPRequestOptions} [options={}] - An object containing query params and headers for the request * @state {HttpState} * @returns {operation} */ declare function _delete(path: string, options?: HTTPRequestOptions): operation; export { _delete as delete, _delete as delete };