Gathering detailed insights and metrics for dotnet-responses
Gathering detailed insights and metrics for dotnet-responses
A collection of response classes that mimic ASP.NET responses
npm install dotnet-responses
Typescript
Module System
Node Version
NPM Version
75.8
Supply Chain
99.5
Quality
76.1
Maintenance
100
Vulnerability
100
License
TypeScript (100%)
Total Downloads
3,133
Last Day
2
Last Week
17
Last Month
66
Last Year
613
172 Commits
1 Watching
2 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
1.8.0
Package Id
dotnet-responses@1.8.0
Unpacked Size
194.52 kB
Size
27.87 kB
File Count
255
NPM Version
8.15.0
Node Version
12.18.2
Cumulative downloads
Total Downloads
Last day
-71.4%
2
Compared to previous day
Last week
-48.5%
17
Compared to previous week
Last month
24.5%
66
Compared to previous month
Last year
-0.5%
613
Compared to previous year
A collection of response classes that mimic ASP.NET responses.
This is a Node.js module available through the npm registry.
1$ npm install dotnet-responses
1const express = require("express"); 2const app = express(); 3const { Ok } = require("dotnet-responses"); 4 5app.get("/ok", function (req, res) { 6 /* 7 Call res.send and send the following object to the client: 8 { 9 "statusCode": 200, 10 "message": "Ok", 11 "data": null, 12 "error": null 13 } 14 */ 15 const ok = new Ok({ res }); 16 ok.send(); 17}); 18 19app.listen(3000);
1const express = require("express"); 2const app = express(); 3const { Ok } = require("dotnet-responses"); 4 5app.get("/ok", function (req, res) { 6 /* 7 Call res.send and send the following object to the client: 8 { 9 "statusCode": 200, 10 "message": "Ok", 11 "data": null, 12 "error": null 13 } 14 */ 15 Ok.send({ res }); 16}); 17 18app.listen(3000);
1const express = require("express"); 2const app = express(); 3const Responses = require("dotnet-responses"); 4 5app.get("/ok", function (req, res) { 6 /* 7 Call res.send and send the following object to the client: 8 { 9 "statusCode": 200, 10 "message": "Ok", 11 "data": null, 12 "error": null 13 } 14 */ 15 Responses.Ok.send({ res }); 16 17 /* 18 Can also do: 19 const ok = new Responses.Ok({ res }); 20 ok.send(); 21 */ 22}); 23 24app.listen(3000);
1const { Ok } = require("dotnet-responses");
2new Ok({
3 res, // Response object from express
4 message, // String (optional)
5 data, // Object or Array (optional)
6});
1const { BadRequest } = require("dotnet-responses"); 2new BadRequest({ 3 res, // Response object from express 4 message, // String (optional) 5 data, // Object or Array (optional) 6 error, // Object (optional) 7});
1const { Response } = require("dotnet-responses"); 2new Response({ 3 statusCode, // Number (optional) 4 message, // String (optional) 5 data, // Object or Array (optional) 6 error, // Object (optional) 7}); 8 9/* 10Response has no functions, it just stores the data passed into its constructor 11 12Response's default data: 13{ 14 "statusCode": 200, 15 "message": null, 16 "data": null, 17 "error": null 18} 19*/
1const express = require("express"); 2const app = express(); 3const { Ok } = require("dotnet-responses"); 4 5app.get("/ok", function(req, res) 6{ 7 // Call res.status to set statusCode to 200 8 // (This example serves no functional purpose, as Ok has a status code of 200 by default) 9 const ok = new Ok({ res }); 10 ok.status( 11 200 // Number 12 ); 13 ok.send(); 14}); 15 16app.listen(3000);
1const express = require("express"); 2const app = express(); 3const { Ok } = require("dotnet-responses"); 4 5app.get("/ok", function(req, res) 6{ 7 // Call res.sendStatus to send response of "Ok" to client 8 const ok = new Ok({ res }); 9 ok.sendStatus( 10 200 // Number 11 ); 12}); 13 14app.listen(3000);
1const express = require("express"); 2const app = express(); 3const { Ok } = require("dotnet-responses"); 4 5app.get("/ok", function(req, res) 6{ 7 /* 8 Call res.send and send the following object to the client: 9 { 10 "statusCode": 200, 11 "message": "Ok", 12 "data": null, 13 "error": null 14 } 15 */ 16 const ok = new Ok({ res }); 17 ok.send(/* No parameters */); 18}); 19 20app.listen(3000);
1const express = require("express"); 2const app = express(); 3const { Ok } = require("dotnet-responses"); 4 5app.get("/ok", function(req, res) 6{ 7 /* 8 Call res.json and send the following object to the client: 9 { 10 "statusCode": 200, 11 "message": "Ok", 12 "data": null, 13 "error": null 14 } 15 */ 16 const ok = new Ok({ res }); 17 ok.json(/* No parameters */); 18}); 19 20app.listen(3000);
1const express = require("express"); 2const app = express(); 3const { Ok } = require("dotnet-responses"); 4 5app.get("/ok", function(req, res) 6{ 7 /* 8 Call res.jsonp and send the following object to the client: 9 { 10 "statusCode": 200, 11 "message": "Ok", 12 "data": null, 13 "error": null 14 } 15 */ 16 const ok = new Ok({ res }); 17 ok.jsonp(/* No parameters */); 18}); 19 20app.listen(3000);
1const express = require("express"); 2const app = express(); 3const { Ok } = require("dotnet-responses"); 4 5app.get("/ok", function(req, res) 6{ 7 // Call res.end 8 const ok = new Ok({ res }); 9 ok.end(/* No parameters */); 10}); 11 12app.listen(3000);
1const express = require("express"); 2const app = express(); 3const { BadRequest } = require("dotnet-responses"); 4 5app.get("/bad-request", function(req, res) 6{ 7 // Call res.status to set statusCode to 400 8 // (This example serves no functional purpose, as BadRequest has a status code of 400 by default) 9 BadRequest.status({ 10 res, // Response object from express 11 statusCode: 400, // Number (optional) 12 }); 13 BadRequest.send({ res }); 14}); 15 16app.listen(3000);
1const express = require("express"); 2const app = express(); 3const { BadRequest } = require("dotnet-responses"); 4 5app.get("/bad-request", function(req, res) 6{ 7 // Call res.sendStatus to send response of "Bad Request" to client 8 BadRequest.sendStatus({ 9 res, // Response object from express 10 statusCode: 400, // Number (optional) 11 }); 12}); 13 14app.listen(3000);
1const express = require("express"); 2const app = express(); 3const { NotFound } = require("dotnet-responses"); 4 5app.get("/*", function(req, res) 6{ 7 /* 8 Call res.send and send the following object to the client: 9 { 10 "statusCode": 404, 11 "message": "Not Found", 12 "data": { 13 "foo": "bar" 14 }, 15 "error": { 16 // Info about your error here 17 } 18 } 19 */ 20 NotFound.send({ 21 res, // Response object from express 22 statusCode: 404, // Number (optional) 23 message: "Not Found", // String (optional) 24 data: { foo: "bar" }, // Object or Array (optional) 25 error: new Error("Page not found"), // Object (optional) 26 }); 27}); 28 29app.listen(3000);
1const express = require("express"); 2const app = express(); 3const { Ok, UnprocessableEntity } = require("dotnet-responses"); 4 5const bodyParser = require("body-parser"); 6app.use(bodyParser.json()); 7app.use(bodyParser.urlencoded({ extended: true })); 8 9const { validateMyPayloadAsync } = require("./some-file-for-custom-validation"); 10 11app.post("/validation-error", function(req, res) 12{ 13 validateMyPayloadAsync(req.body) 14 .then((result) => { 15 /* 16 Call res.json and send the following object to the client: 17 { 18 "statusCode": 200, 19 "message": "Ok", 20 "data": { 21 // Info about result here 22 }, 23 "error": { 24 // Info about your error here 25 } 26 } 27 */ 28 Ok.json({ 29 res, // Response object from express 30 statusCode: 200, // Number (optional) 31 message: "Ok", // String (optional) 32 data: result, // Object or Array (optional) 33 error: new Error("Ok Example"), // Object (optional) 34 }); 35 }) 36 .catch((err) => { 37 /* 38 Call res.json and send the following object to the client: 39 { 40 "statusCode": 422, 41 "message": "Unprocessable Entity", 42 "data": { 43 "foo": "bar" 44 }, 45 "error": { 46 // Info about your err here 47 } 48 } 49 */ 50 UnprocessableEntity.json({ 51 res, // Response object from express 52 statusCode: 422, // Number (optional) 53 message: "Unprocessable Entity",// String (optional) 54 data: { foo: "bar" }, // Object or Array (optional) 55 error: err, // Object (optional) 56 }); 57 }); 58}); 59 60app.listen(3000);
1const express = require("express"); 2const app = express(); 3const { BadRequest } = require("dotnet-responses"); 4 5app.get("/bad-request", function (req, res) { 6 /* 7 Call res.jsonp and send the following object to the client: 8 { 9 "statusCode": 400, 10 "message": "Bad Request", 11 "data": { 12 "foo": "bar" 13 }, 14 "error": { 15 // Info about your err here 16 } 17 } 18 */ 19 BadRequest.jsonp({ 20 res, // Response object from express 21 statusCode: 400, // Number (optional) 22 message: "Bad Request", // String (optional) 23 data: { foo: "bar" }, // Object or Array (optional) 24 error: new Error("Bad Request"), // Object (optional) 25 }); 26}); 27 28app.listen(3000);
1const express = require("express"); 2const app = express(); 3const { Ok } = require("dotnet-responses"); 4 5app.get("/ok", function (req, res) { 6 // Call res.end 7 Ok.end({ 8 res, // Response object from express 9 }); 10}); 11 12app.listen(3000);
ClassName
Continue
SwitchingProtocols
Processing
Ok
Success
Created
Accepted
NonAuthoritativeInformation
NoContent
ResetContent
PartialContent
MultiStatus
AlreadyReported
IMUsed
MultipleChoices
MovedPermanently
Found
SeeOther
NotModified
UseProxy
TemporaryRedirect
PermanentRedirect
BadRequest
Unauthorized
Forbidden
InvalidUrl
NotFound
MethodNotAllowed
NotAcceptable
ProxyAuthenticationError
RequestTimeout
Conflict
Gone
LengthRequired
PreconditionFailed
RequestEntityTooLarge
RequestUriTooLong
UnsupportedMediaType
RequestedRangeNotSatisfiable
ExpectationFailed
UnprocessableEntity
ValidationError
Locked
FailedDependency
UpgradeRequired
PreconditionRequired
TooManyRequests
RequestHeaderFieldsTooLarge
NoResponse
RetryWith
UnavailableForLegalReasons
ClientClosedRequest
InternalServerError
NotImplemented
BadGateway
ServiceUnavailable
GatewayTimeout
HttpVersionNotSupported
VariantAlsoNegotiates
InsufficientStorage
LoopDetected
BandwidthLimitExceeded
NotExtended
NetworkAuthenticationRequired
NetworkReadTimeoutError
NetworkConnectTimeoutError
Response
1const { getResponseByStatusCode } = require("dotnet-responses"); 2 3const Ok = getResponseByStatusCode(200); 4const UnprocessableEntity = getResponseByStatusCode(422); 5const InternalServerError = getResponseByStatusCode(500);
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
No vulnerabilities found.
No security vulnerabilities found.