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
throwbackCompose middleware functions into a single functionservie-lambdaServie transport layer for AWS LambdabusboyA streaming parser for HTML form dataqsandquerystringParse the HTTP query string to an objectconsolidateTemplate rendering
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 numberstartedBoolean indicating if a request/response has startedfinishedBoolean indicating if a request/response has finishedbytesTransferredThe number of bytes sent in the HTTP request/response
Methods
buffer(maxBufferSize): Promise<Buffer>Read the body into aBufferobjecttext(maxBufferSize): Promise<string>Read the body as astringstream(): ReadableRead the body as aReadablestreamsetTimeout(ms): voidSet a timeout on the request or response to be marked as finishedclearTimeout(ms): voidClear a previous timeout
Events
headersEmitted when theheadersobject becomes availabletrailersEmitted when thetrailersobject becomes availablestartedEmitted when the request/response has startedfinishedEmitted when the request/respone has finishedprogressEmitted when thebytesTransferredproperties is incremented
Request
HTTP class for encapsulating a
Request, extendsCommon.
import { Request } from 'servie'Options
const request = new Request({
url: '/',
method: 'GET'
})Extends
Commonoptions.
urlThe HTTP request url (string)method?The HTTP request method (string, default:GET)connection?Connection information ({ remoteAddress?: string, remotePort?: number, localAddress?: string, localPort?: number, encrypted?: boolean })
Properties
urlThe HTTP request url (string)methodThe HTTP request method upper-cased (string)UrlThe HTTP request url as a read-only parsed object (object)connectionConnection information ({})
Methods
abort(): booleanEmit an abort eventerror(message, code, status?, original?): HttpErrorCreate a HTTP error instance
Events
abortEmitted when the request is aborted and MUST be handled by transporterrorEmitted when an out-of-band error occurs (e.g. abort or timeout) and MUST be handled by the transport
Response
HTTP class for encapsulating a
Response, extendsCommon.
import { Response } from 'servie'Options
const response = new Response(request, {})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
HttpError
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