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

Lucas Jellema
0 0
Read Time:1 Minute, 26 Second

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 Post Author

Lucas Jellema

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.
Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %

Average Rating

5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%

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

pgAdmin 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 […]
%d bloggers like this: