{"id":13661029,"url":"https://github.com/serviejs/servie","last_synced_at":"2025-04-07T13:07:53.643Z","repository":{"id":16311893,"uuid":"79413454","full_name":"serviejs/servie","owner":"serviejs","description":"Standard, framework-agnostic HTTP interfaces for JavaScript servers and clients","archived":false,"fork":false,"pushed_at":"2023-12-12T07:21:51.000Z","size":435,"stargazers_count":41,"open_issues_count":4,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-31T11:06:06.702Z","etag":null,"topics":["browser","http","https","interface","node","request","response","servie","standard"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/serviejs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-01-19T03:55:53.000Z","updated_at":"2023-12-12T23:08:18.000Z","dependencies_parsed_at":"2024-01-15T20:51:34.794Z","dependency_job_id":"51a47324-f7bf-4b38-affb-48647e9a876c","html_url":"https://github.com/serviejs/servie","commit_stats":{"total_commits":158,"total_committers":6,"mean_commits":"26.333333333333332","dds":"0.13291139240506333","last_synced_commit":"1ad40240d987601745774de62487bdedf97d3577"},"previous_names":[],"tags_count":47,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serviejs%2Fservie","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serviejs%2Fservie/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serviejs%2Fservie/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serviejs%2Fservie/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/serviejs","download_url":"https://codeload.github.com/serviejs/servie/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247657281,"owners_count":20974345,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["browser","http","https","interface","node","request","response","servie","standard"],"created_at":"2024-08-02T05:01:28.824Z","updated_at":"2025-04-07T13:07:53.622Z","avatar_url":"https://github.com/serviejs.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# ![Servie](https://cdn.rawgit.com/serviejs/servie/master/logo.svg)\n\n[![NPM version](https://img.shields.io/npm/v/servie.svg)](https://npmjs.org/package/servie)\n[![NPM downloads](https://img.shields.io/npm/dm/servie.svg)](https://npmjs.org/package/servie)\n[![Build status](https://img.shields.io/travis/serviejs/servie.svg)](https://travis-ci.org/serviejs/servie)\n[![Test coverage](https://img.shields.io/coveralls/serviejs/servie.svg)](https://coveralls.io/r/serviejs/servie?branch=master)\n[![Bundle size](https://img.shields.io/bundlephobia/minzip/servie.svg)](https://bundlephobia.com/result?p=servie)\n\n\u003e Standard, framework-agnostic HTTP interfaces for JavaScript servers and clients.\n\n## Installation\n\n```\nnpm install servie --save\n```\n\n## Usage\n\n- [`throwback`](https://github.com/serviejs/throwback) Compose middleware functions into a single function\n- [`popsicle`](https://github.com/serviejs/popsicle) HTTP request library for node.js and browsers\n- [`servie-lambda`](https://github.com/serviejs/servie-lambda) Servie transport layer for AWS Lambda\n- [`servie-http`](https://github.com/serviejs/servie-http) Servie transport layer for node.js HTTP\n- [`get-body`](https://github.com/serviejs/get-body) General body parser for forms, JSON and text\n- [`servie-cors`](https://github.com/serviejs/servie-cors) CORS middleware for Servie\n- [`servie-route`](https://github.com/serviejs/servie-route) Routing middleware for Servie\n- [`servie-mount`](https://github.com/serviejs/servie-mount) Mount Servie middleware on a path prefix\n- [`servie-compat-http`](https://github.com/serviejs/servie-compat-http) Mimic node.js HTTP using Servie\n- [`servie-redirect`](https://github.com/serviejs/servie-redirect) Create response objects for redirection\n- [`servie-cookie-store`](https://github.com/serviejs/servie-cookie-store) API for managing client-side cookies\n- [`servie-errorhandler`](https://github.com/serviejs/servie-errorhandler) Standard error handler for transport layers\n- [`servie-finalhandler`](https://github.com/serviejs/servie-finalhandler) Standard final handler for transport layers\n- [`http-errors`](https://github.com/jshttp/http-errors) Create HTTP errors\n- [`boom`](https://github.com/hapijs/boom) HTTP-friendly error objects\n- [`consolidate`](https://github.com/tj/consolidate.js) Template rendering\n\n```ts\nimport { Body, Request, Response, Headers, AbortController } from \"servie\";\n```\n\n\u003e Servie is a universal package, meaning node.js and browsers are supported without needing configuration. This means the primary endpoint requires some `dom` types in TypeScript. When in a node.js, or browser, only environment, prefer importing `servie/dist/{node,browser}` instead.\n\n### `Body`\n\n\u003e Base HTTP class shared between `Request` and `Response`.\n\n```ts\nnew Body(body, headers);\n```\n\n#### Body\n\nSupported body types, depending on environment:\n\n- Node.js - `string | Buffer | ArrayBuffer | Readable | null | undefined`\n- Browser - `string | ArrayBuffer | ReadableStream | null | undefined`\n\n#### Properties and Methods\n\n- `bodyUsed` Boolean whether the body is already consumed\n- `text()` Returns the body as a `Promise\u003cstring\u003e`\n- `json()` Returns the body with `JSON.parse` as `Promise\u003cany\u003e`\n- `arrayBuffer()` Returns the body as a `Promise\u003cArrayBuffer\u003e`\n- `clone()` Clones an unconsumed body\n- `destroy()` Consumes and destroys the body\n\n### `Request`\n\n\u003e HTTP class for modelling a `Request`, extends `Body`.\n\n```ts\nnew Request(input [, init]);\n```\n\n#### Input\n\nA URL string or another `Request` instance to clone from.\n\n#### Init\n\n- `method?` HTTP request method.\n- `body?` Any support body types.\n- `signal?` A signal from an `AbortController`.\n- `headers?` A map, list of tuples, or `Header` instance to initialize from.\n- `trailer?` A promise resolve to a support header initialization types (above).\n\n#### Properties and Methods\n\n- `url` Requested url string\n- `method` Requested method string\n- `signal` Signal event emitter\n- `headers` A [`Headers`](#headers) instance\n- `trailer` A [`Promise\u003cHeaders\u003e`](#headers) instance\n- `clone()` Clones the request into a new instance\n\n### `Response`\n\n\u003e HTTP class for modelling a `Response`, extends `Body`.\n\n```ts\nnew Response([body [, init]]);\n```\n\n#### Body\n\nOne of the support body types (above).\n\n#### Init\n\n- `status?` The numeric HTTP response status code\n- `statusText?` The HTTP response status text\n\n#### Properties and Methods\n\n- `status` The numeric HTTP response status code\n- `statusText` The HTTP response status text\n- `ok` Boolean indicates successful response (`status` between 200 and 299)\n- `headers` A [`Headers`](#headers) instance\n- `trailer` A [`Promise\u003cHeaders\u003e`](#headers) instance\n- `clone()` Clones the response into a new instance\n\n### `Headers`\n\n\u003e Map representation of HTTP headers.\n\n```ts\nnew Headers([init]);\n```\n\n#### Init\n\nInitialize headers from `Iterable\u003cHeaderTuple\u003e`, a `HeadersObject` or an existing `Headers` instance.\n\n#### Methods\n\n- `set(name: string, value: string | string[]): void` Set a HTTP header by overriding case-insensitive headers of the same name\n- `append(name: string, value: string | string[]): void` Append a HTTP header\n- `get(name: string): string | undefined` Retrieve a case-insensitive HTTP header\n- `getAll(name: string): string[]` Retrieve a list of matching case-insensitive HTTP headers\n- `has(name: string): boolean` Check if a case-insensitive header is already set\n- `delete(name: string): void` Delete a case-insensitive header\n- `asObject(): HeadersObject` Return the lower-cased headers as a plain object\n- `extend(obj: HeadersInit): this` Extends the current headers with an object\n- `keys()` Iterable of the available header names\n- `values()` Iterable of header values\n- `entries()` Iterable of headers as `[key, value]`\n- `clear()` Clears the headers instance\n- `clone()` Clones the `Headers` instance\n\n### `AbortController`\n\n\u003e Simple controller for aborting a `Request` instance.\n\n```ts\nnew AbortController();\n```\n\n#### Properties and Methods\n\n- `signal` A [`Signal`](#signal) instance to pass to a [`Request`](#request)\n- `abort()` Used to abort any listening requests through the `signal`\n\n### `Signal`\n\n\u003e Tiny [event emitter](https://github.com/serviejs/events) for communicating during a request.\n\n#### Methods\n\n- `aborted` Boolean indicating whether the request is aborted\n- `on(type, fn)` Attach an event listener to an event type\n- `off(type, fn)` Remove an event listener from an event type\n- `each(fn)` Attach an event listener for all events\n- `none(fn)` Remove a global event listener\n- `emit(type, ...args)` Emit an event to all listeners\n\n#### Standard Events\n\n- `abort` The request has been aborted\n- `requestBytes` Emitted on request progress with current bytes\n- `requestEnded` The request has ended\n- `requestStarted` The request has been started\n- `responseBytes` Emitted on response progress with current bytes\n- `responseEnded` The response has ended\n- `responseStarted` The response has started\n\nPlugins can emit new types of events.\n\n## Implementation\n\nIf you're building the transports for Servie, there are some life cycle events you need to be aware of:\n\n1. Listen to the `error` event on `signal` for errors\n2. Listen to the `abort` event on `signal` to destroy the connection\n3. Resolve `trailer` promise and append to HTTP request or response\n4. There are some existing built-in type-safe events in `SignalEvents` you can support\n\n## JavaScript\n\nThis module is designed for ES2017 environments and published with [TypeScript](https://github.com/Microsoft/TypeScript) definitions on NPM.\n\n## License\n\nApache 2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserviejs%2Fservie","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fserviejs%2Fservie","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserviejs%2Fservie/lists"}