https://github.com/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.
https://github.com/kth/http-responses
http javascript npm
Last synced: 8 months ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/kth/http-responses
- Owner: KTH
- License: mit
- Created: 2020-04-01T20:17:38.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-09-29T04:19:14.000Z (over 2 years ago)
- Last Synced: 2025-07-06T09:50:28.975Z (9 months ago)
- Topics: http, javascript, npm
- Language: JavaScript
- Homepage:
- Size: 271 KB
- Stars: 0
- Watchers: 9
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
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
[Demo code source here](https://github.com/KTH/http-responses/tree/master/demo-app/).
```javascript
const express = require("express");
const httpResponse = require("@kth/http-responses");
const app = express();
app.get("/", function (request, response) {
httpResponse.ok(request, response, "
Hello world!");
});
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");
});
```
```json
{
"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": "paddy@kth.se",
"license": "MIT",
"dependencies": {
"@kth/http-responses": "^1.0.20",
"express": "^4.17.1"
}
}
```