better-response
v1.0.2
Published
Lightweight wrapper around Javascript's Response class
Readme
Better Response
BetterResponse is a lightweight wrapper around the Response class in JavaScript, designed to simplify response creation and enhance control over caching and JSON serialization.
Installation
To use BetterResponse, simply include it in your project. You can install it via npm:
npm install better-responseHere's a quick example of how to import BetterResponse in your project:
import BetterResponse from "better-response";Features
Automatic JSON Stringify
BetterResponse automatically converts objects to JSON and sets the appropriate headers, streamlining the process of creating JSON responses.
// Using BetterResponse
new BetterResponse({ hello: "world" });
// Using Response
new Response(JSON.stringify({ hello: "world" }), {
headers: { "Content-Type": "application/json" }
});Cache Control
BetterResponse provides convenient caching options to manage response caching times.
// Default Caching
new BetterResponse("Cache is amazing!", { status: 200, cache: "default" });
// Custom Cache Duration (in milliseconds)
new BetterResponse("Cache is amazing!", { status: 200, cache: 1000 * 60 }); // Cache for 1 minuteLicense
BetterResponse is licensed under the MIT License. See the LICENSE file for more details.
