Search Results

Request and Response Properties

Request Properties

When using the JavaScript code to create your own stages for the request side, the following request object properties are available to use:

  • info - Request information, such as host, referrer, and remoteAddress. See below for details.

  • query - An incoming request URI query component (the key-value part of the URI between ‘?’ and ‘#’). The query is parsed into its individual key-value pairs (using the qs module) and stored in req.query. For example, req.query.status && /all/.test(req.query.status).

  • headers - The raw request headers. Each header is represented as a key value pair and stored in the req.headers object. Note that these headers are what’s received from the clients, rather than the ones to eventually be forwarded to the backend services; the headers to be forwarded to the backend services are those defined in the request header whitelist, as well as those added or “allowed” by the request Custom Javascript. Refer to Custom Headers for more information.

    You can use console.log(req.headers) to list all the available headers in custom Javascript.

  • payload - The request payload.

  • params - The path parameters of the request. For example, if you have an operation defined as GET /users/{userId}/books/{bookId} and the actual request’s URL is http://localhost:3000/users/34/books/8989, this will result in the following parameters:

    req.params: { "userId": "34", "bookId": "8989" }

req.info

Microflow® exposes the req.info property for the request object in the Custom Request stage. Use this property with the console.log function, you can obtain the following request information from the Microflow app log after sending a request to the Microflow endpoint:

  • host - content of the HTTP ‘Host’ header (e.g. ‘example.com:8080’).
  • hostname - the host name of the ‘Host’ header (e.g. ‘example.com’).
  • received - request reception timestamp.
  • referrer - content of the HTTP ‘Referrer’ (or ‘Referer’) header.
  • remoteAddress - remote client IP address.
  • remotePort - remote client port.
  • responded - request response timestamp (0 is not responded yet).

Take the POST/pet operation of the Petstore REST service as an example, add the following JavaScript code in the Custom Request stage:

console.log('******************************');
console.log(req.info);
console.log('=================================');
done(req);

Send a POST operation when the Microflow app is successfully pushed and run. You can get the request details in the app log:

Response Properties

When using the JavaScript code to create your own stages, the following response object properties are available to use:

  • headers - The raw response headers returned back from the backend service. Each header is represented as a key value pair and stored in the res.headers object. You can use console.log(res.headers) to list all the available headers in custom JavaScript. Be note that these headers are what’s received from the backend services, rather than the ones to be forwarded back to the clients; the headers to be forwarded to the clients are those defined in response header whitelist, as well as those added or “allowed” by the response Custom JavaScript. Refer to Custom Headers for more information.

  • body - The payload object of the response received from the backend service.

  • statusCode - The status code of the response received from the backend service.