@kth/http-responses
v1.0.84
Published
Simpel standardized http responses.
Downloads
42
Readme
HTTP Responses
Npm: @kth/http-responses
Simple ways of returning responses in a declarative way without status codes. Note that it is not async so use it for simple smal stuff.
Demo application
const express = require("express");
const httpResponse = require("@kth/http-responses");
const app = express();
app.get("/", function (request, response) {
httpResponse.ok(request, response, "<!DOCTYPE html><h1>Hello world!<h1>");
});
app.get("/_monitor", function (request, response) {
httpResponse.ok(
request,
response,
"APPLICATION_STATUS: OK",
httpResponse.contentTypes.PLAIN_TEXT
);
});
app.get("/error5xx.html", function (request, response) {
httpResponse.internalServerError(request, response, "Internal Server Error");
});
app.get("/favicon.ico", function (request, response) {
httpResponse.noContent(request, response);
});
app.use(function (request, response) {
httpResponse.notFound(request, response, "Page not found");
});
app.listen(80, function () {
console.log("Server started");
});
{
"name": "Demo",
"version": "1.0.0",
"description": "Demo app for @kth/http-responses",
"main": "index.js",
"scripts": {
"clean": "rm -r ./node_modules && rm package-lock.json"
},
"author": "[email protected]",
"license": "MIT",
"dependencies": {
"@kth/http-responses": "^1.0.20",
"express": "^4.17.1"
}
}