Oracle Cloud Infrastructure Functions and Project Fn – Retrieving Headers, Query Parameters and other HTTP Request elements

0

Functions on Oracle Cloud Infrastructure are implemented using Project Fn. A function runs in Docker container. This container has a runtime (for example for Java, Go, Python, Node) and a minimal handler to handle an HTTP request and turn it into a call to the function. When writing the code to implement the function, we do not need to be aware of this layout. The FDK wrapper hands our Node function or Java method one or more parameters from which we can take what we need in terms of input.

image

For example with a Node implementation, our function gets parameter input which contains the input payload, taken from the HTTP request’s body. We can also accept a second argument – by convention called ctx. This argument gives us a handle to many details from the original triggering HTTP request:

  • headers
  • full URL path – including all path-segments and query parameters
  • Fn runtime details (CPU, memory, version, Fn call id, ..)
  • Function meta data (OCID for application and function)
  • HTTP Method (GET, POST, PUT, …)
  • OPC Request Id
  • IP of the requesting system

The ctx parameter looks like this for an HTTP request:

image

Standard headers such as Host, User-Agent, Content-Type can be accessed under _headers in the context parameters. Custom HTTP Headers are included with a special prefix: Fn-Http-H-

image

The original URL can be found in _headers using the key “Fn-Http-Request-Url”. The HTTP Method is available under “Fn-Http-Method”.

image

With the data available in the context, we can interpret many details from the original HTTP request and respond accordingly.

Note: in these screenshots, some of the headers were added by the OCI API Gateway that sat between my HTTP client (Postman) and the Function running on OCI.


About Author

Lucas Jellema, active in IT (and with Oracle) since 1994. Oracle ACE Director and Oracle Developer Champion. Solution architect and developer on diverse areas including SQL, JavaScript, Kubernetes & Docker, Machine Learning, Java, SOA and microservices, events in various shapes and forms and many other things. Author of the Oracle Press book Oracle SOA Suite 12c Handbook. Frequent presenter on user groups and community events and conferences such as JavaOne, Oracle Code, CodeOne, NLJUG JFall and Oracle OpenWorld.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.