express-respond-simple
Simple helpers which create an express middleware, which responds 200 OK
, or any other valid
code. Optional response body as a string or object can be supplied.
Install
npm install --save express-respond-simple
Use
;;; const app = ; // status code by number:app;app; // Will actually respond '204 No Content' instead of '200 OK' if no body is givenapp; // Will respond '200 OK' with an empty bodyapp; // equivalently, by name:app;app; // Will actually respond '204 No Content' instead of '200 OK' if no body is givenapp; // Will respond '200 OK' with an empty bodyapp; app;
$ curl --include http://localhost:3000/healthHTTP/1.1 200 OKX-Powered-By: ExpressContent-Type: application/json; charset=utf-8Content-Length: 17ETag: W/"11-sn4NhG2LGN3PiYCfMneoRg"Date: Tue, 05 Jan 2016 01:38:39 GMTConnection: keep-alive {"status":"good"} $ curl --include http://localhost:3000/emptyHTTP/1.1 204 No ContentX-Powered-By: ExpressETag: W/"a-oQDOV50e1MN2H/N8GYi+8w"Date: Tue, 05 Jan 2016 01:39:45 GMTConnection: keep-alive $ curl --include http://localhost:3000/empty-force-200HTTP/1.1 200 OKX-Powered-By: ExpressContent-Type: text/plain; charset=utf-8Content-Length: 0ETag: W/"0-1B2M2Y8AsgTpgAmY7PhCfg"Date: Wed, 06 Jan 2016 06:59:56 GMTConnection: keep-alive $ curl --include http://localhost:3000/paywallHTTP/1.1 402 Payment RequiredX-Powered-By: ExpressContent-Type: text/plain; charset=utf-8Content-Length: 49ETag: W/"31-0PQSlh/LwV6MQ515vkAE9w"Date: Tue, 05 Jan 2016 01:42:43 GMTConnection: keep-alive Please add credits to your account and try again.
License
MIT