Package Exports
- servie
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (servie) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Servie provides standard, framework-agnostic HTTP interfaces for servers and clients.
Installation
npm install servie --saveUsage
Common
Base HTTP class for common request and response logic.
import { Common } from 'servie'Options
headers?HTTP headers (Headers | HeadersObject | string[])trailers?HTTP trailers (Headers | HeadersObject | string[])events?An event emitter object (EventEmitter)body?Allowed HTTP bodies (string | Buffer | Readable | object)
Properties
eventsThe request/response event emitterheadersThe submitted headers as aHeadersinstancetrailersThe submitted trailers as aHeadersinstancebodyThe submitted body payloadbodyUsedA boolean indicating where the body was readtypeA shorthand property for reading and writing theContent-TypeheaderlengthA shorthand property for reading and writingContent-Lengthas a number
Methods
buffer(maxBufferSize): Promise<Buffer>Read the body into aBufferobjecttext(maxBufferSize): Promise<string>Read the body as astringjson(maxBufferSize): Promise<object>Read the body as a JSON payloadstream(): ReadableRead the body as aReadablestream
Events
headersEmitted when theheadersobject becomes availabletrailersEmitted when thetrailersobject becomes available
Request
HTTP class for encapsulating a
Request, extendsCommon.
import { Request } from 'servie'Options
Extends
Commonoptions.
urlThe HTTP request url (string)method?The HTTP request method (string, default:GET)
Properties
urlThe HTTP request url (string)methodThe HTTP request method upper-cased (string)UrlThe HTTP request url as a parsed object (object)
Methods
destroy(): HttpErrorEmit an abort eventerror(message, code, status?, original?): HttpErrorCreate a HTTP error instance
Events
destroyEmitted when the request is destroyed/aborted
Response
HTTP class for encapsulating a
Response, extendsCommon.
import { Response } from 'servie'Options
Extends
Commonoptions.
status?The HTTP response status code (number)statusText?The HTTP response status message (string)
Properties
status?The HTTP response status code (number)statusText?The HTTP response status message (string)
Headers
Used by
CommonforRequestandResponseobjects.
Options
Take a single parameter with the headers in object, array or Headers format.
Properties
rawThe raw HTTP headers list (string[])
Methods
object(obj?: HeadersObject | null): HeadersObject | voidA getter/setter method for reading the headers as a lower-cased object (like node.js)set(name: string, value: string | string[]): thisSet a HTTP header by overriding case-insensitive headers of the same nameappend(name: string, value: string | string[]): thisAppend a HTTP headerget(name: string): string | undefinedRetrieve a case-insensitive HTTP headergetAll(name: string): string[]Retrieve a list of matching case-insensitive HTTP headershas(name: string): booleanCheck if a case-insensitive header is already setdelete(name: string): thisDelete a case-insensitive header
HTTP Error
Internally and externally triggered HTTP errors.
Properties
codeA unique error code (string)statusA HTTP status code (number)requestTheRequestinstance that triggered the error (Request)messageStandard error message (string)causeSpecified when the HTTP error was triggered by an underlying error
JavaScript
This module is designed for ES5 environments, but also requires Promise to be available.
TypeScript
This project is written using TypeScript and publishes the definitions directly to NPM.
License
MIT