errand worker component used for rest APIs
npm install errand-rest-client
Notes:
- For dependencies and suggested usage of errand worker components refer to errand
- Set environment variable ERRAND_MONGODB_URL with connection string for mongodb server, if not set module will default to
mongodb://localhost:27017
{
"tasks": [
{
"task": "errand-rest-client",
"data": {
"description": "replace-with-task-description",
"request": {
"database": "replace-with-mongodb-database-name",
"collection": "replace-with-name-of-target-collection-for-result",
"method": "replace-with-rest-client-method",
"parameters": {
...
}
}
}
}
]
}
Notes:
- tasks - errand task list
-
tasks[].task - required
errand-rest-client
task name - tasks[].data.description - optional task description
- tasks[].data.request.database - required mongodb database name
- tasks[].data.request.collection - required mongodb collection used with request, used for either payload for request or response from request
- tasks[].data.request.method - required rest client method
- tasks[].data.request.parameters - required rest client method parameters, the parameter payload will vary depending on method
{
"tasks": [
{
"task": "errand-mongodb",
"data": {
"description": "replace-with-task-description",
"request": {
"database": "replace-with-mongodb-database-name",
"collection": "replace-with-name-of-target-collection-for-result",
"method": "get.array.into.collection",
"parameters": {
"url": "replace-with-rest-API-endpoint",
"index":"replace-with-key-to-use-for-upserting-results",
"request":{},
"helpers": [
{ "replace": { "regexp":"\\$date", "newSubstr": "date"}}
]
}
}
}
}
]
}
Notes:
- tasks[].data.request.parameters.url - use to define URL for API request.
- tasks[].data.request.parameters.index - used to define key to be used for upserting results.
- tasks[].data.request.parameters.helpers - used to add helpers to transform response.
{
"tasks": [
{
"task": "errand-mongodb",
"data": {
"description": "replace-with-task-description",
"request": {
"database": "replace-with-mongodb-database-name",
"collection": "replace-with-name-of-target-collection-for-result",
"method": "put.array.from.collection",
"parameters": {
"url": "replace-with-rest-API-endpoint"
}
}
}
}
]
}
Notes:
- tasks[].data.request.parameters.url - use to define URL for API request.
{
"tasks": [
{
"task": "errand-mongodb",
"data": {
"description": "replace-with-task-description",
"request": {
"database": "replace-with-mongodb-database-name",
"collection": "replace-with-name-of-target-collection-for-result",
"method": "put.array.from.collection.withID",
"parameters": {
"url": "replace-with-rest-API-endpoint-containing-{{id}}",
"id": "replace-with-field-to-use-as-document-id"
}
}
}
}
]
}
Notes:
-
tasks[].data.request.parameters.url - use to define URL for API request, URL contains a
{{id}}
which is replaced with tasks[].data.request.parameters.id value -
tasks[].data.request.parameters.id - used to define document ID, most likely when working with mongodb this field will contain
_id