Text variants
Variants of type text define the text body and the status code to be sent when a route is requested.
Options
The options property in a variant of type text must be an object containing next properties:
status(Number): Status code to send.body(String): Text to send as body of the request response.headers(Object): Object containing headers to set in the response. Optional.
module.exports = [
  {
    id: "get-users",
    url: "/api/users",
    method: "GET",
    variants: [
      {
        id: "error",
        type: "text", // variant of type text
        options: {
          status: 403, // status to send
          headers: { // response headers to send
            "x-custom-header": "foo-header-value",
          },
          body: "An error ocurred"
        },
      }
    ]
  }
];
Response headers
By default, the text variant type sets a Content-Type header in the response with value text/plain; charset=utf-8, but it can be changed using the headers option.
- Default headers
 - Custom headers
 
module.exports = [
  {
    id: "get-user",
    url: "/api/text",
    method: "GET",
    variants: [
      {
        id: "success",
        type: "text", // variant of type json
        options: {
          status: 200,
          body: "Foo body"
        },
      }
    ]
  }
];
note
The response will have the Content-Type=text/plain; charset=utf-8 header.
module.exports = [
  {
    id: "get-user",
    url: "/api/text",
    method: "GET",
    variants: [
      {
        id: "success",
        type: "text", // variant of type json
        options: {
          status: 200,
          headers: {
            "Content-Type": "text/html; charset=utf-8"
          },
          body: "<div>Foo body</div>"
        },
      }
    ]
  }
];
note
The response will have the Content-Type=text/html; charset=utf-8 header.