1.0.2 • Published 12 months ago

better-response v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

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-response

Here'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 minute

License

BetterResponse is licensed under the MIT License. See the LICENSE file for more details.

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago