Skip to main content

cht@1.0.8

get(path, options, [callback])
post(path, body, options, [callback])
put(path, options, [callback])
request(method, path, data, options, [callback])

This adaptor exports the following from common:

cursor()
dataPath()
dataValue()
dateFns
each()
field()
fields()
fn()
lastReferenceValue()
merge()
sourceValue()

Functions

get

get(path, options, [callback]) ⇒ Operation

Make a GET request against the base URL.

ParamTypeDescription
pathstringPath to resource
optionsRequestOptionsOptions to configure the HTTP request
[callback]functionOptional callback to handle the response

This operation writes the following keys to state:

State KeyDescription
datathe parsed response body
responsethe response from the CHT HTTP server, including headers, statusCode, body, etc
referencesan array of all previous data objects used in the Job

Example: Get a list of contacts

get("/api/v2/export/contacts");

Example: Filter contacts given a name

get("/api/v2/export/contacts", {
query: {"filters": {
"search": "jim"
}}
});

post

post(path, body, options, [callback]) ⇒ Operation

Make a POST request against the base url

ParamTypeDescription
pathstringPath to resource
bodyobjectObject which will be attached to the POST body
optionsRequestOptionsOptional request options
[callback]functionOptional callback to handle the response

This operation writes the following keys to state:

State KeyDescription
datathe parsed response body
responsethe response from the CHT HTTP server, including headers, statusCode, body, etc
referencesan array of all previous data objects used in the Job

Example: Create a new person

post("/api/v1/people", {  
"name": "Hannah",
"phone": "+254712345678",
"type": "contact",
"contact_type": "patient", });

put

put(path, options, [callback]) ⇒ Operation

Make a PUT request against the base url

ParamTypeDescription
pathstringPath to resource
optionsRequestOptionsOptions to configure the HTTP request
[callback]functionOptional callback to handle the response

This operation writes the following keys to state:

State KeyDescription
datathe parsed response body
responsethe response from the CHT HTTP server, including headers, statusCode, body, etc
referencesan array of all previous data objects used in the Job

Example: Update settings

put("/api/v1/settings",{query:{overwrite:true}});

request

request(method, path, data, options, [callback]) ⇒ Operation

Make a general HTTP request to CHT

ParamTypeDescription
methodstringHTTP method to use
pathstringPath to resource
dataobjectObject which will be attached to the POST body
optionsRequestOptionsOptional request options
[callback]functionOptional callback to handle the response

This operation writes the following keys to state:

State KeyDescription
datathe parsed response body
responsethe response from the CHT HTTP server, including headers, statusCode, body, etc
referencesan array of all previous data objects used in the Job

Example

request("POST","/api/v1/people", {  
"name": "Hannah",
"phone": "+254712345678",
"type": "contact",
"contact_type": "patient", });

Interfaces

RequestOptions

Options provided to the HTTP request

Properties

NameTypeDescription
bodyobject | stringbody data to append to the request. JSON will be converted to a string (but a content-type header will not be attached to the request).
errorsobjectMap of errorCodes -> error messages, ie, { 404: 'Resource not found;' }. Pass false to suppress errors for this code.
formobjectPass a JSON object to be serialised into a multipart HTML form (as FormData) in the body.
queryobjectAn object of query parameters to be encoded into the URL.
headersobjectAn object of headers to append to the request.
parseAsstringParse the response body as json, text or stream. By default will use the response headers.
timeoutnumberRequest timeout in ms. Default: 300 seconds.