Unfortunately the functions docs are very, very superficial and neither contain any information on how to access the incoming request (e.g. HTTP headers, source IP, etc.) nor on how to return anything else than text responses.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
There are several properties available in the application’s context called
__ow_headers
,__ow_path
,__ow_method
which provide additional information about the calling context. These are available as arguments to the function. The first is the request headers, the second is the path segment (after your function name), and the last is the HTTP verb used to invoke the function. In addition the values__ow_query
and__ow_body
may be present (the latter base64 encoded) for binary and non-JSON input types. Here is an example JavaScript/Typescript repo that demonstrates how to use these.Thanks for the feedback. Here are some examples in Node.js to get you started. If you prefer other languages let us know but it’s the same model
function to perform an HTTP redirect
set a cookie and return some html
return image/png (or other binary content, must be base64 encode
return json (default response)
The
statusCode
is optional and defaults to 200 OK. Theheaders
are also optional. Thebody
is required for a valid response. (This is the same as AWS Lambda.)Want to learn more? Join the DigitalOcean Community!
Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.
Sign up now
This comment has been deleted