Trigger CC via HTTP
You can trigger a CloudCode Task via HTTP. This is referred to as a Web Task.
In this way, CloudCode can be used to create a JSON-based HTTP API.
The task will need to have the "Web Request" trigger enabled in the task's configuration.
The hostnames (with .poweredbyjourney.com suffix) for an app's web-triggered CloudCode tasks are configured by editing an app deployment in the Deployments workspace in OXIDE.
After deploying, enabled tasks are accessible on https://<your_app_deployment_hostname>.poweredbyjourney.com/<task>.
Note that domain names are globally unique, so care is required when choosing hostnames for each of your apps and app deployments. Consider using the organization name, app name, and a -testing or -staging suffix for the corresponding deployments. e.g.
https://acme-my-app-testing.poweredbyjourney.com/my_web_task,https://acme-my-app-staging.poweredbyjourney.com/my_web_task,https://acme-my-app.poweredbyjourney.com/my_web_task.
A Minimal Example
Here's a minimal example of a task that can handle GET requests:
// This MUST be defined, and either return access.unauthorized() or access.authorized().
export async function authenticate({request, access}) {
return access.authorized();
}
export async function get({params, request, response}) {
return {hello: 'world'};
}Authentication Example
This is an example implementation of authentication for a POST request.
Request and Response Details
Limitations
Custom domains are not supported - only
*.poweredbyjourney.com.Custom paths are not supported.
Only
application/jsonis supported for request format, andapplication/json,text/htmlortext/plainfor response format. Binary data specifically is not supported.
Web tasks running longer than 60 seconds
It is recommended that developers keep web tasks running for fewer than 60 seconds in total.
Once a task reaches more than 60 seconds the behavior is as follows:
After 60 seconds, another invocation is scheduled in a new process, with a new trace ID, while the previous one is still running. This repeats for 3x invocations total.
After 3 minutes, the client gets a 504 Gateway Timeout response.
If one of the retries happens to complete in less than 60 seconds, and before a total of 3 minutes, the client gets that response.
Each invocation shows "COMPLETED", even though the client never saw the response.
Last updated
