All Products
Search
Document Center

Function Compute:Event handlers

Last Updated:Apr 01, 2026

In a Custom Container runtime, Function Compute communicates with your container over HTTP. This page explains the HTTP contract your server must implement to handle event-driven function invocations, and provides a working Node.js example.

How it works

When a Custom Container function is invoked, Function Compute forwards the request to the HTTP server running inside your container. The runtime cycle follows these steps:

  1. Receive the invocation — Function Compute sends a POST request to /invoke with the event payload in the request body and common request headers in the request headers.

  2. Process the event — Extract the context and event parameters from the request headers and body, then run your business logic.

  3. Return the result — Send an HTTP response with the handler return value, an HTTP status code, and the x-fc-status response header.

  4. Report errors — If the invocation fails, set x-fc-status to a non-success value so Function Compute records the error stack in logs.

For event handler implementations using function signatures from FC-supported runtimes (such as the Go runtime), see Event handlers in a custom runtime.

POST /invoke

The HTTP server must handle POST /invoke for function invocations, and optionally POST /initialize for instance initialization (Initializer hook).

Request

FieldValue
MethodPOST
Path/invoke
Content-Typeapplication/octet-stream
Request bodyThe event payload specified when calling InvokeFunction
Request headersCommon request headers
Important

Content-Type must be application/octet-stream.

Response

The response body is the return value of the handler. Include both fields in every response:

FieldType200404
HTTP status code (StatusCode)HTTP response statusSucceededFailed
x-fc-statusResponse headerSucceededFailed
Always set both StatusCode and x-fc-status in your HTTP response.

What happens when `x-fc-status` is omitted

If x-fc-status is absent, Function Compute treats the invocation as successful even when an error occurs inside the handler. Business logic may not be affected, but errors are not recorded — reducing the observability of your function. The following figure shows an example.

image8hanshujisuanruntime

What happens when `x-fc-status` is set

When x-fc-status is present, Function Compute uses its value to determine whether the invocation succeeded. On failure, the error stack is recorded in logs. The following figure shows an example.

image9runtimefc

Node.js example

The following Node.js Express example implements both the Initializer hook (POST /initialize) and the event handler (POST /invoke). The context and event parameters are read from req.headers and req.body.

'use strict';

const express = require('express');

// The constants.
const PORT = 9000;
const HOST = '0.0.0.0';
const app = express();
// Parse the JSON-formatted request body.
app.use(express.json({type:['application/json', 'application/octet-stream']}))


// The example of the Initializer hook. You must configure the initializer hook when you create the function.
app.post('/initialize', (req, res) => {
  console.log(req.body)
  res.send('Hello FunctionCompute, /initialize\n');
});


// Invoke the event function.
app.post('/invoke', (req, res) => {
  console.log(req.body)
  res.send('Hello FunctionCompute, event function\n');
});

var server = app.listen(PORT, HOST);
console.log(`Running on http://${HOST}:${PORT}`);

server.timeout = 0; // Never time out.
server.keepAliveTimeout = 0; // keepalive, never timeout

Examples for other languages

Use Serverless Devs to deploy and invoke Custom Container event functions with minimal setup. The following GitHub repositories provide ready-to-run examples:

FAQ