Closed hunterachieng closed 1 month ago
Looking great Hunter!
One last thing. Looking at the satusehat
docs, they also use PUT and for some reason PATCH requests. I don't think they use DELETE.
So we need to add put()
and patch()
.
To reduce the amount of repetition, can we first add a request()
operation, an then make get
, post
,put
and patch
very thin wrappers around it:
This untested code, but this is what I mean:
// Change the utils import so that we don't clash with `request`
import util from './Utils';
// GENERIC REQUEST OPERATION (can be used in job code)
export function request(method, data = null, path, params = {}, callback = s => s) {
return async state => {
const [resolvedPath, resolvedData, resolvedParams] = expandReferences(
state,
path,
params
);
try {
const response = await util.request( // note that I am using util. here
state.configuration,
`/${resolvedPath}`,
{
method
params: resolvedParams,
data: resolvedData // NOTE - you might have to only add the data key if data is truthy. Try this first.
}
);
return util.prepareNextState(state, response, callback); // note that I am using util. here
} catch (e) {
throw e.body ?? e;
}
};
}
// WRAPPED GET OPERATION
export function get(path, params, callback) {
return request('get', path, null, params, callback)
}
Summary
Create a satusehat adaptor
Details
We are implementing a new adaptor:
satusehat
with a genericpost
andget
methodsIssues
529
Review Checklist
Before merging, the reviewer should check the following items: