# 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 &#x60;end()&#x60; too, in which case it never leaves.


### Retorna

{{% notice tip %}}
**Tipo:** `RequestSpec`
<br>

{{% /notice %}}

---
## accept(type)


Sets Accept, accepting the same shorthands.

### Parámetros

| Nombre | Tipo | Opcional | Descripción |
| :--- | :--- | :---: | :--- |
| **type** | `string` | ❌ |  |

### Retorna

{{% notice tip %}}
**Tipo:** `RequestSpec`
<br>

{{% /notice %}}

---
## addEventListener(event, callback)


component-emitter&#x27;s alias for &#x60;on&#x60;, which is what superagent&#x27;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

{{% notice tip %}}
**Tipo:** `RequestSpec`
<br>

{{% /notice %}}

---
## addListener(event, callback)


superagent&#x27;s alias for &#x60;on&#x60; in Node, where the request is an EventEmitter.

### Parámetros

| Nombre | Tipo | Opcional | Descripción |
| :--- | :--- | :---: | :--- |
| **event** | `string` | ❌ |  |
| **callback** | `function` | ❌ |  |

### Retorna

{{% notice tip %}}
**Tipo:** `RequestSpec`
<br>

{{% /notice %}}

---
## 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)&#x3D;` | ❌ | &#x60;{ filename, contentType }&#x60;, or just a filename. |

### Retorna

{{% notice tip %}}
**Tipo:** `RequestSpec`
<br>

{{% /notice %}}

---
## auth(user, pass, options)


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

### Parámetros

| Nombre | Tipo | Opcional | Descripción |
| :--- | :--- | :---: | :--- |
| **user** | `string` | ❌ |  |
| **pass** | `(string|object)&#x3D;` | ❌ |  |
| **options** | `object&#x3D;` | ❌ |  |

### Retorna

{{% notice tip %}}
**Tipo:** `RequestSpec`
<br>

{{% /notice %}}

---
## 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

{{% notice tip %}}
**Tipo:** `RequestSpec`
<br>

{{% /notice %}}

---
## emit(event)



### Parámetros

| Nombre | Tipo | Opcional | Descripción |
| :--- | :--- | :---: | :--- |
| **event** | `string` | ❌ |  |
| **args** | `...*` | ❌ |  |

### Retorna

{{% notice tip %}}
**Tipo:** `boolean`
<br>
whether anything was listening.
{{% /notice %}}

---
## end(callback)


Sends the request.

### Parámetros

| Nombre | Tipo | Opcional | Descripción |
| :--- | :--- | :---: | :--- |
| **callback** | `function` | ❌ | &#x60;(error, response)&#x60;, superagent&#x27;s signature. |

### Retorna

{{% notice tip %}}
**Tipo:** `RequestSpec`
<br>

{{% /notice %}}

---
## eventNames()




### Retorna

{{% notice tip %}}
**Tipo:** `Array&lt;string&gt;`
<br>
the events with at least one listener.
{{% /notice %}}

---
## field(name, value)


Adds a plain multipart field.

### Parámetros

| Nombre | Tipo | Opcional | Descripción |
| :--- | :--- | :---: | :--- |
| **name** | `string` | ❌ |  |
| **value** | `*` | ❌ |  |

### Retorna

{{% notice tip %}}
**Tipo:** `RequestSpec`
<br>

{{% /notice %}}

---
## get(field)


Reads a header back, case-insensitively.

### Parámetros

| Nombre | Tipo | Opcional | Descripción |
| :--- | :--- | :---: | :--- |
| **field** | `string` | ❌ |  |

### Retorna

{{% notice tip %}}
**Tipo:** `*`
<br>

{{% /notice %}}

---
## getHeader(field)


superagent&#x27;s alias for &#x60;get&#x60;.

### Parámetros

| Nombre | Tipo | Opcional | Descripción |
| :--- | :--- | :---: | :--- |
| **field** | `string` | ❌ |  |

### Retorna

{{% notice tip %}}
**Tipo:** `*`
<br>

{{% /notice %}}

---
## getMaxListeners()


Inert, for symmetry with setMaxListeners.


### Retorna

{{% notice tip %}}
**Tipo:** `number`
<br>

{{% /notice %}}

---
## hasListeners(event)


component-emitter&#x27;s own predicate.

### Parámetros

| Nombre | Tipo | Opcional | Descripción |
| :--- | :--- | :---: | :--- |
| **event** | `string` | ❌ |  |

### Retorna

{{% notice tip %}}
**Tipo:** `boolean`
<br>
whether anything is listening.
{{% /notice %}}

---
## key()


Inert: TLS material belonged to the Node agent.



---
## listenerCount(event)



### Parámetros

| Nombre | Tipo | Opcional | Descripción |
| :--- | :--- | :---: | :--- |
| **event** | `string` | ❌ |  |

### Retorna

{{% notice tip %}}
**Tipo:** `number`
<br>

{{% /notice %}}

---
## listeners(event)



### Parámetros

| Nombre | Tipo | Opcional | Descripción |
| :--- | :--- | :---: | :--- |
| **event** | `string` | ❌ |  |

### Retorna

{{% notice tip %}}
**Tipo:** `Array&lt;function&gt;`
<br>

{{% /notice %}}

---
## 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&#x27;s &#x60;off(event)&#x60; did.

### Parámetros

| Nombre | Tipo | Opcional | Descripción |
| :--- | :--- | :---: | :--- |
| **event** | `string` | ❌ |  |
| **callback** | `function&#x3D;` | ❌ |  |

### Retorna

{{% notice tip %}}
**Tipo:** `RequestSpec`
<br>

{{% /notice %}}

---
## 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

{{% notice tip %}}
**Tipo:** `RequestSpec`
<br>

{{% /notice %}}

---
## on(event, callback)



### Parámetros

| Nombre | Tipo | Opcional | Descripción |
| :--- | :--- | :---: | :--- |
| **event** | `string` | ❌ |  |
| **callback** | `function` | ❌ |  |

### Retorna

{{% notice tip %}}
**Tipo:** `RequestSpec`
<br>

{{% /notice %}}

---
## once(event, callback)



### Parámetros

| Nombre | Tipo | Opcional | Descripción |
| :--- | :--- | :---: | :--- |
| **event** | `string` | ❌ |  |
| **callback** | `function` | ❌ |  |

### Retorna

{{% notice tip %}}
**Tipo:** `RequestSpec`
<br>

{{% /notice %}}

---
## 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

{{% notice tip %}}
**Tipo:** `RequestSpec`
<br>

{{% /notice %}}

---
## pfx()


Inert: TLS material belonged to the Node agent.



---
## prependListener(event, callback)



### Parámetros

| Nombre | Tipo | Opcional | Descripción |
| :--- | :--- | :---: | :--- |
| **event** | `string` | ❌ |  |
| **callback** | `function` | ❌ |  |

### Retorna

{{% notice tip %}}
**Tipo:** `RequestSpec`
<br>

{{% /notice %}}

---
## prependOnceListener(event, callback)



### Parámetros

| Nombre | Tipo | Opcional | Descripción |
| :--- | :--- | :---: | :--- |
| **event** | `string` | ❌ |  |
| **callback** | `function` | ❌ |  |

### Retorna

{{% notice tip %}}
**Tipo:** `RequestSpec`
<br>

{{% /notice %}}

---
## 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

{{% notice tip %}}
**Tipo:** `RequestSpec`
<br>

{{% /notice %}}

---
## rawListeners(event)


superagent&#x27;s alias for &#x60;listeners&#x60;.

### Parámetros

| Nombre | Tipo | Opcional | Descripción |
| :--- | :--- | :---: | :--- |
| **event** | `string` | ❌ |  |

### Retorna

{{% notice tip %}}
**Tipo:** `Array&lt;function&gt;`
<br>

{{% /notice %}}

---
## 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&#x3D;` | ❌ | every event when omitted. |

### Retorna

{{% notice tip %}}
**Tipo:** `RequestSpec`
<br>

{{% /notice %}}

---
## removeEventListener(event, callback)


component-emitter&#x27;s alias for &#x60;off&#x60;.

### Parámetros

| Nombre | Tipo | Opcional | Descripción |
| :--- | :--- | :---: | :--- |
| **event** | `string` | ❌ |  |
| **callback** | `function&#x3D;` | ❌ |  |

### Retorna

{{% notice tip %}}
**Tipo:** `RequestSpec`
<br>

{{% /notice %}}

---
## removeListener(event, callback)


superagent&#x27;s alias for &#x60;off&#x60;.

### Parámetros

| Nombre | Tipo | Opcional | Descripción |
| :--- | :--- | :---: | :--- |
| **event** | `string` | ❌ |  |
| **callback** | `function&#x3D;` | ❌ |  |

### Retorna

{{% notice tip %}}
**Tipo:** `RequestSpec`
<br>

{{% /notice %}}

---
## responseType(type)



### Parámetros

| Nombre | Tipo | Opcional | Descripción |
| :--- | :--- | :---: | :--- |
| **type** | `string` | ❌ | &#x60;blob&#x60; is the only value the library uses. |

### Retorna

{{% notice tip %}}
**Tipo:** `RequestSpec`
<br>

{{% /notice %}}

---
## 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 &#x60;hooks.beforeStart&#x60; callback reading &#x60;get(&#x27;Content-Type&#x27;)&#x60; sees what it
always saw. Repeated calls merge.

### Parámetros

| Nombre | Tipo | Opcional | Descripción |
| :--- | :--- | :---: | :--- |
| **data** | `*` | ❌ |  |

### Retorna

{{% notice tip %}}
**Tipo:** `RequestSpec`
<br>

{{% /notice %}}

---
## 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

{{% notice tip %}}
**Tipo:** `RequestSpec`
<br>

{{% /notice %}}

---
## set(field, value)


Sets one header, or every header in an object.

### Parámetros

| Nombre | Tipo | Opcional | Descripción |
| :--- | :--- | :---: | :--- |
| **field** | `(string|object)` | ❌ |  |
| **value** | `*` | ❌ |  |

### Retorna

{{% notice tip %}}
**Tipo:** `RequestSpec`
<br>
itself, for chaining.
{{% /notice %}}

---
## setMaxListeners()


Inert: there is no listener ceiling to raise.


### Retorna

{{% notice tip %}}
**Tipo:** `RequestSpec`
<br>

{{% /notice %}}

---
## sortQuery()


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



---
## timeout(options)


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

### Parámetros

| Nombre | Tipo | Opcional | Descripción |
| :--- | :--- | :---: | :--- |
| **options** | `(number|object)` | ❌ |  |

### Retorna

{{% notice tip %}}
**Tipo:** `RequestSpec`
<br>

{{% /notice %}}

---
## toJSON()




### Retorna

{{% notice tip %}}
**Tipo:** `object`
<br>
the request as data, as superagent&#x27;s &#x60;toJSON&#x60; did.
{{% /notice %}}

---
## type(type)


Sets Content-Type, accepting superagent&#x27;s shorthands (&#x60;json&#x60;, &#x60;form&#x60;, …).

### Parámetros

| Nombre | Tipo | Opcional | Descripción |
| :--- | :--- | :---: | :--- |
| **type** | `string` | ❌ |  |

### Retorna

{{% notice tip %}}
**Tipo:** `RequestSpec`
<br>

{{% /notice %}}

---
## unset(field)


Removes a header, whatever case it was set in.

### Parámetros

| Nombre | Tipo | Opcional | Descripción |
| :--- | :--- | :---: | :--- |
| **field** | `string` | ❌ |  |

### Retorna

{{% notice tip %}}
**Tipo:** `RequestSpec`
<br>

{{% /notice %}}

---
## use(fn)


Applies a plugin, superagent&#x27;s extension point.

### Parámetros

| Nombre | Tipo | Opcional | Descripción |
| :--- | :--- | :---: | :--- |
| **fn** | `function` | ❌ | receives this request. |

### Retorna

{{% notice tip %}}
**Tipo:** `RequestSpec`
<br>

{{% /notice %}}

---
## withCredentials(on)


Sends cookies and HTTP auth on cross-origin requests.

### Parámetros

| Nombre | Tipo | Opcional | Descripción |
| :--- | :--- | :---: | :--- |
| **on** | `boolean&#x3D;` | ❌ | defaults to true, as superagent&#x27;s did. |

### Retorna

{{% notice tip %}}
**Tipo:** `RequestSpec`
<br>

{{% /notice %}}

---

