https://github.com/serviejs/servie-send
Generate a HTTP response with client-side cache support
https://github.com/serviejs/servie-send
body cache etag send servie typescript
Last synced: 10 months ago
JSON representation
Generate a HTTP response with client-side cache support
- Host: GitHub
- URL: https://github.com/serviejs/servie-send
- Owner: serviejs
- License: other
- Created: 2017-05-09T16:24:16.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2023-12-12T07:34:07.000Z (over 2 years ago)
- Last Synced: 2024-12-15T04:46:46.976Z (over 1 year ago)
- Topics: body, cache, etag, send, servie, typescript
- Language: TypeScript
- Size: 155 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Servie Send
[](https://npmjs.org/package/servie-send)
[](https://npmjs.org/package/servie-send)
[](https://travis-ci.org/serviejs/servie-send)
[](https://coveralls.io/r/serviejs/servie-send?branch=master)
> Create a HTTP response to send using Servie - a thin layer for creating a `Response` object with cache headers.
## Installation
```
npm install servie-send --save
```
## Usage
```ts
import {
sendText,
sendHtml,
sendJson,
sendStream,
sendEmpty,
entityTag
} from "servie-send";
function handle(req) {
return sendText(req, "hello world!");
return sendHtml(req, "");
return sendJson(req, { json: true });
return sendStream(req, fs.createReadStream("example.txt"));
return sendEmpty(req); // Nothing in response.
}
```
### Options
- `status?` Change the default response status code (200).
- `headers?` Define the headers to use for the response.
- `contentType?` Define content length for the response.
- `contentLength?` Define content length for the response.
- `mtime?` Define the modification `Date` for the response.
- `etag?` Define an ETag for the response (e.g. pre-computed with `entityTag()` or `true` for on-demand).
## TypeScript
This project is written using [TypeScript](https://github.com/Microsoft/TypeScript) and publishes the definitions directly to NPM.
## License
Apache 2.0