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.
export default request => {};
The first parameter of the function is Request
containing basic information of the received request:
body
the bodyheaders
the headershostname
the hostname of the incoming requestmethod
the method of the incoming requesturl
request URL string. This contains only the URL that is present in the actual HTTP request.query
the parsed querystringfunctionName
the function namefunctionUid
the uid of the functionexport 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.