Interface Response

Response - The response object.

Hierarchy

  • Response

Methods

  • Send error response.

    Parameters

    • code: number

      The status code.

    • message: string

      The error message.

    Returns Response

    • The response object.

    Example

    res.error(404, "Not found");
    res.error(500, "Internal server error");
    res.error(404, "Not found").json({ message: "Not found" });
  • Set response header.

    Parameters

    • field: string

      The header field.

    • value: string

      The header value.

    Returns Response

    • The response object.

    Example

    res.header("Content-Type", "application/json");
    res.header("Content-Type", "text/html");
    res.header("Content-Type", "text/plain");
    res.header("Content-Type", "text/plain").status(200);
  • Send json response.

    Parameters

    • body: any

      The response body.

    Returns Response

    • The response object.

    Example

    res.json({ message: "OK" });
    res.json({ message: "Not found" });
    res.json({ message: "Internal server error" });
    res.json({ message: "OK" }).status(200);
  • Redirect to path.

    Parameters

    • path: string

      The redirect path.

    Returns Response

    • The response object.

    Example

    res.redirect("/path/to/redirect");
    res.redirect("/path/to/redirect").status(200);
    res.redirect("/path/to/redirect").json({ message: "OK" });
    res.redirect("/path/to/redirect").json({ message: "OK" }).status(200);
  • Send response.

    Parameters

    • body: any

      The response body.

    Returns Response

    • The response object.

    Example

    res.send({ message: "OK" });
    res.send({ message: "Not found" });
    res.send({ message: "Internal server error" });
    res.send({ message: "OK" }).status(200);
  • Send file.

    Parameters

    • path: string

      The file path.

    Returns Response

    • The response object.

    Example

    res.sendFile("/path/to/file");
    res.sendFile("/path/to/file").status(200);
  • Set return status code.

    Parameters

    • code: number

      The status code.

    Returns Response

    • The response object.

    Example

    res.status(200);
    res.status(404);
    res.status(500);
    res.status(200).json({ message: "OK" });

Generated using TypeDoc