Request and Response

This section describes the Request and Response API present in the function

Fleet Function is able to handle HTTP requests directly in the same way that you handle request and response using expressjs or fastify in your Node.js environment.

Request

export default request => {};

The first parameter of the function is Request containing basic information of the received request:

  • body the body
  • headers the headers
  • hostname the hostname of the incoming request
  • method the method of the incoming request
  • url request URL string. This contains only the URL that is present in the actual HTTP request.
  • query the parsed querystring
  • functionName the function name
  • functionUid the uid of the function

Response

export default (request, response) => {};

The second parameter of the function is Response, very similar to the fastify API, it contains the following objects:

  • code(statusCode) Sets the status code.
  • getHeader(key) Retrieves the header defined before.
  • hasHeader(key) Check if a header has been set.
  • redirect(url, code?) Redirect to the specified URL, code is optional (Default value 302).
  • removeHeader(key) Remove the value of a previously set header.
  • send(payload) Sends the payload to the user, it can be plain text, a buffer, JSON or an Error object.
  • serializer(function) Sets a custom serializer for the payload.
  • setHeader(key, value) Sets a response header.
  • type(type) Sets the header Content-Type.