5.0.4 • Published 8 years ago

@yr/agent v5.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
8 years ago

NPM Version Build Status

Extension to superagent to support collapsing request queues, response duration, and a status code of 504 for timedout requests.

Usage

const agent = require('@yr/agent');

agent
  .get('http://some/api')
  .timeout(1000)
  .retry(3)
  .then((res) => {
    console.log(res.body);
    console.log(res.duration);
  })
  .catch((err) => {
    // handle error...
  });

API

get(url, options): GET request for url. Returns superagent Request instance. Behaviour is configurable with the following options properties:

  • abort: abort existing (outstanding) request to same url (default false)
  • id: optional string for tagging request
  • ignoreQuery: ignore query parameters of url when matching existing, oustanding requests for the same url (default false)

Default behaviour is to return a cached Request instance for the same url (request collapsing). Setting both abort and ignoreQuery to true will automatically abort an outstanding request with a different query parameter:

agent
  .get('http://some/api?search=foo')
  .then((res) => {
    // Aborted, won't fire
  });
agent
  .get('http://some/api?search=bar')
  .then((res) => {
    console.log(res.body);
  });

Although the full Superagent API is supported, it's recommended to use then() (Promises) instead of end() to allow for request collapsing

abortAll(filter): abort all outstanding requests. Takes optional string or function filter. If filter is defined as a string, only aborts requests that are tagged with options.id. If filter is defined as function, only aborts requests that return true for filter(req).

agent
  .get('http://some/api', { id: 'foo' })
  .then((res) => {
    // Aborted, won't fire
  });

agent.abortAll('foo');
5.0.4

8 years ago

5.0.3

8 years ago

5.0.2

8 years ago

5.0.1

8 years ago

5.0.0

8 years ago

5.0.0-rc1

8 years ago

4.5.0

9 years ago

4.3.4

9 years ago

4.3.3

9 years ago

4.3.2

9 years ago

4.3.1

9 years ago

4.3.0

9 years ago

4.2.1

9 years ago

4.2.0

9 years ago

4.1.0

9 years ago

4.0.1

9 years ago

4.0.0

9 years ago

3.4.0

9 years ago

3.3.3

9 years ago

3.3.2

9 years ago

3.3.1

9 years ago

3.3.0

9 years ago

3.2.2

9 years ago

3.2.1

9 years ago

3.2.0

9 years ago

3.1.0

9 years ago

3.0.2

9 years ago

3.0.1

10 years ago

3.0.0

10 years ago

2.0.0

10 years ago

1.1.1

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago