Subsections of http

Request Spec

constructor

Parámetros

Nombre Tipo Opcional Descripción
method string the HTTP verb.
url string the whole URL, query string included.

abort()

Cancels the request. Works before `end()` too, in which case it never leaves.

Retorna

Tip

Tipo: RequestSpec


accept(type)

Sets Accept, accepting the same shorthands.

Parámetros

Nombre Tipo Opcional Descripción
type string

Retorna

Tip

Tipo: RequestSpec


addEventListener(event, callback)

component-emitter's alias for `on`, which is what superagent's browser request carries. Missed on the first pass because the surface was enumerated from client.js source text, and component-emitter mixes its methods in at runtime rather than assigning them there. Caught in review by Chema.

Parámetros

Nombre Tipo Opcional Descripción
event string
callback function

Retorna

Tip

Tipo: RequestSpec


addListener(event, callback)

superagent's alias for `on` in Node, where the request is an EventEmitter.

Parámetros

Nombre Tipo Opcional Descripción
event string
callback function

Retorna

Tip

Tipo: RequestSpec


agent()

Inert: there is no Node HTTP agent to configure.


attach(name, file, options)

Adds a multipart file. A string is a path, as it was under superagent.

Parámetros

Nombre Tipo Opcional Descripción
name string
file *
options `(string object)=`

Retorna

Tip

Tipo: RequestSpec


auth(user, pass, options)

Sets an Authorization header. Basic by default, as in a browser; `{ type: 'bearer' }` sends the first argument as a token.

Parámetros

Nombre Tipo Opcional Descripción
user string
pass `(string object)=`
options object=

Retorna

Tip

Tipo: RequestSpec


buffer()

Inert: buffering was a Node response concern.


ca()

Inert: TLS material belonged to the Node agent.


cert()

Inert: TLS material belonged to the Node agent.


clearTimeout()

Cancels the timers without cancelling the request.

Retorna

Tip

Tipo: RequestSpec


emit(event)

Parámetros

Nombre Tipo Opcional Descripción
event string
args ...*

Retorna

Tip

Tipo: boolean
whether anything was listening.


end(callback)

Sends the request.

Parámetros

Nombre Tipo Opcional Descripción
callback function `(error, response)`, superagent's signature.

Retorna

Tip

Tipo: RequestSpec


eventNames()

Retorna

Tip

Tipo: Array<string>
the events with at least one listener.


field(name, value)

Adds a plain multipart field.

Parámetros

Nombre Tipo Opcional Descripción
name string
value *

Retorna

Tip

Tipo: RequestSpec


get(field)

Reads a header back, case-insensitively.

Parámetros

Nombre Tipo Opcional Descripción
field string

Retorna

Tip

Tipo: *


getHeader(field)

superagent's alias for `get`.

Parámetros

Nombre Tipo Opcional Descripción
field string

Retorna

Tip

Tipo: *


getMaxListeners()

Inert, for symmetry with setMaxListeners.

Retorna

Tip

Tipo: number


hasListeners(event)

component-emitter's own predicate.

Parámetros

Nombre Tipo Opcional Descripción
event string

Retorna

Tip

Tipo: boolean
whether anything is listening.


key()

Inert: TLS material belonged to the Node agent.


listenerCount(event)

Parámetros

Nombre Tipo Opcional Descripción
event string

Retorna

Tip

Tipo: number


listeners(event)

Parámetros

Nombre Tipo Opcional Descripción
event string

Retorna

Tip

Tipo: Array<function>


maxResponseSize()

Inert: the response is read whole, as it was in a browser.


off(event, callback)

Removes one listener, or every listener for the event when no function is given – which is what component-emitter's `off(event)` did.

Parámetros

Nombre Tipo Opcional Descripción
event string
callback function=

Retorna

Tip

Tipo: RequestSpec


ok(fn)

Overrides what counts as a successful response.

Parámetros

Nombre Tipo Opcional Descripción
fn function receives the response, returns whether to resolve.

Retorna

Tip

Tipo: RequestSpec


on(event, callback)

Parámetros

Nombre Tipo Opcional Descripción
event string
callback function

Retorna

Tip

Tipo: RequestSpec


once(event, callback)

Parámetros

Nombre Tipo Opcional Descripción
event string
callback function

Retorna

Tip

Tipo: RequestSpec


parse(fn)

Replaces the parser used on the response body.

Parámetros

Nombre Tipo Opcional Descripción
fn function receives the response text, returns the body.

Retorna

Tip

Tipo: RequestSpec


pfx()

Inert: TLS material belonged to the Node agent.


prependListener(event, callback)

Parámetros

Nombre Tipo Opcional Descripción
event string
callback function

Retorna

Tip

Tipo: RequestSpec


prependOnceListener(event, callback)

Parámetros

Nombre Tipo Opcional Descripción
event string
callback function

Retorna

Tip

Tipo: RequestSpec


query(value)

Appends to the query string. Takes an object or an already-encoded string.

Parámetros

Nombre Tipo Opcional Descripción
value `(string object)`

Retorna

Tip

Tipo: RequestSpec


rawListeners(event)

superagent's alias for `listeners`.

Parámetros

Nombre Tipo Opcional Descripción
event string

Retorna

Tip

Tipo: Array<function>


redirects()

Inert: XHR and fetch always follow redirects; superagent could not disable that in a browser.


removeAllListeners(event)

Parámetros

Nombre Tipo Opcional Descripción
event string= every event when omitted.

Retorna

Tip

Tipo: RequestSpec


removeEventListener(event, callback)

component-emitter's alias for `off`.

Parámetros

Nombre Tipo Opcional Descripción
event string
callback function=

Retorna

Tip

Tipo: RequestSpec


removeListener(event, callback)

superagent's alias for `off`.

Parámetros

Nombre Tipo Opcional Descripción
event string
callback function=

Retorna

Tip

Tipo: RequestSpec


responseType(type)

Parámetros

Nombre Tipo Opcional Descripción
type string `blob` is the only value the library uses.

Retorna

Tip

Tipo: RequestSpec


retry()

Inert: retrying is not reproduced, because half a retry policy is worse than none.


send(data)

Attaches a body, and picks the Content-Type the way superagent did – at this point, not at send time, so a `hooks.beforeStart` callback reading `get('Content-Type')` sees what it always saw. Repeated calls merge.

Parámetros

Nombre Tipo Opcional Descripción
data *

Retorna

Tip

Tipo: RequestSpec


serialize(fn)

Replaces the serializer used for an object body.

Parámetros

Nombre Tipo Opcional Descripción
fn function receives the body, returns a string.

Retorna

Tip

Tipo: RequestSpec


set(field, value)

Sets one header, or every header in an object.

Parámetros

Nombre Tipo Opcional Descripción
field `(string object)`
value *

Retorna

Tip

Tipo: RequestSpec
itself, for chaining.


setMaxListeners()

Inert: there is no listener ceiling to raise.

Retorna

Tip

Tipo: RequestSpec


sortQuery()

Inert: the query string is built by the caller, in order.


timeout(options)

Sets the deadline for the whole request, or `{ deadline, response }` for both that and the time allowed before a response starts arriving.

Parámetros

Nombre Tipo Opcional Descripción
options `(number object)`

Retorna

Tip

Tipo: RequestSpec


toJSON()

Retorna

Tip

Tipo: object
the request as data, as superagent's `toJSON` did.


type(type)

Sets Content-Type, accepting superagent's shorthands (`json`, `form`, …).

Parámetros

Nombre Tipo Opcional Descripción
type string

Retorna

Tip

Tipo: RequestSpec


unset(field)

Removes a header, whatever case it was set in.

Parámetros

Nombre Tipo Opcional Descripción
field string

Retorna

Tip

Tipo: RequestSpec


use(fn)

Applies a plugin, superagent's extension point.

Parámetros

Nombre Tipo Opcional Descripción
fn function receives this request.

Retorna

Tip

Tipo: RequestSpec


withCredentials(on)

Sends cookies and HTTP auth on cross-origin requests.

Parámetros

Nombre Tipo Opcional Descripción
on boolean= defaults to true, as superagent's did.

Retorna

Tip

Tipo: RequestSpec