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

Lucas Jellema

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.


Leave a Reply

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

Next Post

pgAdmin in Docker: Provisioning connections and passwords

Facebook0TwitterLinkedinpgAdmin is a popular open source and feature rich administration and development platform for PostgreSQL. When provisioning Postgres database environments using containers, it is not unusual to also provision a pgAdmin container. The pgAdmin image provided on Docker Hub does not contain any server connection details. When your pgAdmin container […]