Skip to content

Releases: sindresorhus/got

5.1.0

04 Nov 06:18
Compare
Choose a tag to compare
  • 5205e72 body option now accepts Stream1 streams
  • e45087a content-length and accept headers now can be falsy values ('' or 0 for example)
  • dcc7de6 response property is now non-enumerable in error object
  • cf54459 undefined value of code property in error removed

v5.0.0...v5.1.0

5.0.0

18 Oct 09:45
Compare
Choose a tag to compare

zjvxrhf

Retries

We added retries on network failures with noisy exponential backoff. By default got will try five times, before returning error.

Retries only applies to network errors (because network is not reliable). Requests with server errors, like 50x status codes, will not be retried.

You can disable them by passing 0 to retries option.

Update

$ npm install --save got@5

Highlights

Changes

v4.2.0...v5.0.0

4.2.0

09 Sep 09:02
Compare
Choose a tag to compare
  • e944467 improves error message on invalid JSON
  • e0863dc enable errors in stream mode (#97)
  • 3182234 allow requests via domain sockets

v4.1.1...v4.2.0

4.1.1

28 Jul 15:03
Compare
Choose a tag to compare
  • bdc1bfb fixes crashes on RequestError in Promise mode

v4.1.0...v4.1.1

4.1.0 - x-www-form-urlencoded

27 Jul 11:15
Compare
Choose a tag to compare
  • 7bea9c4 If body is a plain Object, it will be stringified and sent as application/x-www-form-urlencoded.

v4.0.0...v4.1.0

4.0.0

25 Jul 07:08
Compare
Choose a tag to compare

Major release with lots of new stuff! Enjoy!

anigif_enhanced-buzz-14210-1427585395-12

Promise API

got without callback now returns a promise instead of a stream. The stream API now lives under stream property (look at the end of section).

got('todomvc.com')
    .then(function (res) {
        console.log(res.body);
    })
    .catch(function (err) {
        console.error(err.response.body);
    });

In resolve handler you receive a http.response object with body as additional property.

In reject handler we provide an Error object. Unless Error type is RequestError, it will have response property with body property.

This API will be a huge advantage with co and Generators:

var co = require('co');

co(function * () {
    try {
        var response = yield got('todomvc.com');
        console.log(response.body);
    } catch (err) {
        console.error(err);
    }
});

You can go even further with destructuring and await from ES7:

async function () {
    try {
        var {body} = await got('todomvc.com');
        console.log(body);
    } catch (err) {
        console.error(err);
    }
}

Stream support is preserved, but now under the streams property:

got.stream('todomvc.com').pipe(process.stdout);

New Errors

Before 4.0.0 got had one Error class (GotError) with nested stack traces and custom error messages. This was a nice concept, but in production use some edge cases popped out:

  • Error stacks are too long.
  • Relevant information often were in one or two levels deep (eg. error.nested.nested).
  • Errors message are hard to parse for url.

So we decided to review Errors in new version. In 4.0.0 got now have multiple Error classes for different situations: RequestError, ReadError, ParseError, HTTPError and MaxRedirectsError.

In addition to message and code properties from the original error, the new errors types also provide additional properties (host, hostname, path and method) for logging and debugging.

Infinity-agent removed

Custom agent was removed. This returns the ability to configure or replace global Agent, but also returns low maxSockets value in NodeJS 0.10.x. To fix this you can add this lines at the top of your app (not in reusable modules!):

require('http').globalAgent.maxSockets = Infinity;
require('https').globalAgent.maxSockets = Infinity;

Changes

v3.3.1...v4.0.0

3.3.1

16 Jul 01:22
Compare
Choose a tag to compare
  • 312c80d Don't parse JSON on 204 responses. #78
  • 79f1390 Emit response event only on final request. #75
  • b9c33aa Reselect agent on redirect from HTTP to HTTPS. #80

v3.3.0...v3.3.1

3.3.0

30 Jun 15:51
Compare
Choose a tag to compare
  • 87d98e1 Added content-length header in requests with body.
  • d7a66ba Fallback on pathname option, if no path is present.

v3.2.0...v3.3.0

3.2.0

09 May 07:46
Compare
Choose a tag to compare

json option now sets Accept header to application/json (if it was not specified in headers)

v3.1.0...v3.2.0

3.1.0

09 May 07:44
Compare
Choose a tag to compare

error event now have additional body and response arguments in callback:

got('http://giggle.com')
    .on('error', function (error, body, response) {
        console.log(error, body, response);
    });

v3.0.0...v3.1.0