OpenShift Serverless Functions is a Technology Preview feature only. Technology Preview features are not supported with Red Hat production service level agreements (SLAs) and might not be functionally complete. Red Hat does not recommend using them in production. These features provide early access to upcoming product features, enabling customers to test functionality and provide feedback during the development process.

For more information about the support scope of Red Hat Technology Preview features, see https://access.redhat.com/support/offerings/techpreview/.

OpenShift Serverless Functions provides templates that can be used to create basic functions for the following runtimes:

This guide provides reference information that you can use to develop functions.

Node.js context object reference

The context object has several properties that can be accessed by the function developer.

log

Provides a logging object that can be used to write output to the cluster logs. The log adheres to the Pino logging API.

Example log
function handle(context) {
  context.log.info(Processing customer);
}

You can access the function by using the curl command to invoke it:

Example command
$ curl http://example.com
Example output
{"level":30,"time":1604511655265,"pid":3430203,"hostname":"localhost.localdomain","reqId":1,"msg":"Processing customer"}

query

Returns the query string for the request, if any, as key-value pairs. These attributes are also found on the context object itself.

Example query
function handle(context) {
  // Log the 'name' query parameter
  context.log.info(context.query.name);
  // Query parameters are also attached to the context
  context.log.info(context.name);
}

You can access the function by using the curl command to invoke it:

Example command
$ curl http://example.com?name=tiger
Example output
{"level":30,"time":1604511655265,"pid":3430203,"hostname":"localhost.localdomain","reqId":1,"msg":"tiger"}

body

Returns the request body if any. If the request body contains JSON code, this will be parsed so that the attributes are directly available.

Example body
function handle(context) {
  // log the incoming request body's 'hello' parameter
  context.log.info(context.body.hello);
}

You can access the function by using the curl command to invoke it:

Example command
$ curl -X POST -d '{"hello": "world"}' -H 'Content-type: application/json' http://example.com
Example output
{"level":30,"time":1604511655265,"pid":3430203,"hostname":"localhost.localdomain","reqId":1,"msg":"world"}

headers

Returns the HTTP request headers as an object.

Example header
function handle(context) {
  context.log.info(context.headers["custom-header"]);
}

You can access the function by using the curl command to invoke it:

Example command
$ curl -H 'x-custom-header: some-value’' http://example.com
Example output
{"level":30,"time":1604511655265,"pid":3430203,"hostname":"localhost.localdomain","reqId":1,"msg":"some-value"}

HTTP requests

method

Returns the HTTP request method as a string.

httpVersion

Returns the HTTP version as a string.

httpVersionMajor

Returns the HTTP major version number as a string.

httpVersionMinor

Returns the HTTP minor version number as a string.