Build your own API endpoint, by writing Javascript to handle the request.
This is experimental, and may change or disappear some day, with little notice.
The code is the body of a function, that gets the request as R, and returns the response. It has
100ms to run. R has these fields:
R.method: The request method, like "GET".
R.headers: The request headers, as a plain object. Names are lowercase, like
R.headers["user-agent"]. If a header is repeated in the request, its values are joined with
", ".
R.extraPath: The path after the encoded code in the URL. For
/run/{code}/foo/bar, this is "/foo/bar".
R and R.headers are read-only, and trying to change them throws an error. To set
response headers, return them in the headers field.
The returned object can have these fields, all optional:
status: The response status code, between 200 and 599. Default: 200.
headers: The response headers, as an object of names to a string, or to a list of strings for a
repeated header. Like {"x-one": "1", "x-many": ["a", "b"]}.
body: The response body. A string is sent as is, and anything else is sent as JSON.
For example, to respond with the request's user agent:
return {
headers: {"content-type": "text/plain"},
body: "You are " + R.headers["user-agent"]
}