# fugot

> Like got but with futures

Latest version **1.0.0** (published 2017-08-15) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install fugot
pnpm add fugot
yarn add fugot
bun add fugot
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2017-08-15 |
| First published | 2016-09-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4.0.0 |
| Dependencies | 9 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Juan Soto |
| Maintainers | sotojuan |
| Keywords | future, fluture, fantasy-land, functional, monad, burrito, promise, http, https, get, got, url, uri, request, util, utility, simple, curl, wget, fetch |

## Links

- npm: https://www.npmjs.com/package/fugot
- Repository: https://github.com/sotojuan/fugot
- Homepage: https://github.com/sotojuan/fugot#readme
- Issues: https://github.com/sotojuan/fugot/issues
- npm.io page: https://npm.io/package/fugot

## Dependencies (9)

- [is-stream](https://npm.io/package/is-stream.md) ^1.1.0
- [timed-out](https://npm.io/package/timed-out.md) ^4.0.1
- [get-stream](https://npm.io/package/get-stream.md) ^3.0.0
- [is-redirect](https://npm.io/package/is-redirect.md) ^1.0.0
- [url-parse-lax](https://npm.io/package/url-parse-lax.md) ^1.0.0
- [lowercase-keys](https://npm.io/package/lowercase-keys.md) ^1.0.0
- [unzip-response](https://npm.io/package/unzip-response.md) ^3.0.0
- [is-retry-allowed](https://npm.io/package/is-retry-allowed.md) ^1.1.0
- [create-error-class](https://npm.io/package/create-error-class.md) ^3.0.2

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2017-08-15
- 0.3.3 — 2017-02-27
- 0.3.2 — 2017-02-23
- 0.3.1 — 2017-01-20
- 0.3.0 — 2016-11-06
- 0.2.0 — 2016-09-27
- 0.1.0 — 2016-09-25

## README

# fugot

[![Build Status](https://travis-ci.org/sotojuan/fugot.svg?branch=master)](https://travis-ci.org/sotojuan/fugot)

> Like [`got`](https://github.com/sindresorhus/got) but with [Futures](https://github.com/fluture-js/Fluture)

This library is a port of the excellent `got` Node HTTP client that returns Futures instead of Promises, provided by the also excellent [Fluture](https://github.com/fluture-js/Fluture) library.

Please note that unlike `got`, `fugot` **does not support streams** as it's focused on being a Future-returning client for Node.

## Install

```
$ npm install --save fluture fugot
```

## Why Futures?

Futures offer an interesting alternative to Promises with the following features:

* [Lazy evaluation](https://github.com/fluture-js/Fluture/wiki/Comparison-to-Promises#eagerness-vs-laziness)
* [Fantasy Land](https://github.com/fantasyland/fantasy-land) spec compliance
* [Cancellation](https://github.com/fluture-js/Fluture#future)
* [Resource management](https://github.com/fluture-js/Fluture#resource-management)

Fluture offers a nice API that provides [transformation](https://github.com/fluture-js/Fluture#transforming-futures), [error handling](https://github.com/fluture-js/Fluture#error-handling), and [parallelism](https://github.com/fluture-js/Fluture#parallelism) methods.

For a more in-depth comparison, see [Fluture's wiki](https://github.com/fluture-js/Fluture/wiki/Comparison-to-Promises).

## Usage

```js
const fugot = require('fugot')
// Because you'll probably be making your own Futures, they're exposed by `fugot`
const Future = fugot.Future

// Requests don't run until you call `fork`
const firstName = fugot('http://api.randomuser.me', {json: true})
  .map(data => data.body.results[0])
  .map(result => result.name.first)

// Prints a random first name
firstName.fork(console.error, console.log)

// Call the function returned by `fork` to cancel a request
const cancel = firstName.fork(console.error, console.log)
// Nothing should be printed unless you comment the following out
cancel()
```

### API

These docs are copied from `got` with appropiate modifications.

#### fugot(url, [options])

A `GET` request by default, but that can be changed in `options`.

Returns a Future for a `response` object with a `body` property, a `url` property with the request URL or the final URL after redirects, and a `requestUrl` property with the original request URL.

##### url

Type: `string`, `object`

The URL to request or a [`http.request` options](https://nodejs.org/api/http.html#http_http_request_options_callback) object.

Properties from `options` will override properties in the parsed `url`.

##### options

Type: `object`

Any of the [`http.request`](http://nodejs.org/api/http.html#http_http_request_options_callback) options.

###### body

Type: `string`, `buffer`, `readableStream`, `object`

Body that will be sent with a `POST` request.

If present in `options` and `options.method` is not set, `options.method` will be set to `POST`.

If `content-length` or `transfer-encoding` is not set in `options.headers` and `body` is a string or buffer, `content-length` will be set to the body length.

If `body` is a plain object, it will be stringified with [`querystring.stringify`](https://nodejs.org/api/querystring.html#querystring_querystring_stringify_obj_sep_eq_options) and sent as `application/x-www-form-urlencoded`.

###### encoding

Type: `string`, `null`<br>
Default: `'utf8'`

Encoding to be used on `setEncoding` of the response data. If `null`, the body is returned as a Buffer.

###### json

Type: `boolean`<br>
Default: `false`

Parse response body with `JSON.parse` and set `accept` header to `application/json`.

###### query

Type: `string`, `object`<br>

Query string object that will be added to the request URL. This will override the query string in `url`.

###### timeout

Type: `number`, `object`

Milliseconds to wait for a server to send response headers before aborting request with `ETIMEDOUT` error.

Option accepts `object` with separate `connect` and `socket` fields for connection and socket inactivity timeouts

###### retries

Type: `number`, `function`<br>
Default: `5`

Number of request retries when network errors happens. Delays between retries counts with function `1000 * Math.pow(2, retry) + Math.random() * 100`, where `retry` is attempt number (starts from 0).

Option accepts `function` with `retry` and `error` arguments. Function must return delay in milliseconds (`0` return value cancels retry).

**Note:** if `retries` is `number`, `ENOTFOUND` and `ENETUNREACH` error will not be retried (see full list in [`is-retry-allowed`](https://github.com/floatdrop/is-retry-allowed/blob/master/index.js#L12) module).

###### followRedirect

Type: `boolean`<br>
Default: `true`

Defines if redirect responses should be followed automatically.

## Thanks

* [Sindre Sorhus](https://github.com/sindresorhus) for `got` and the docs
* [Aldwin Vlasblom](https://github.com/Avaq) for `fluture`

## License

MIT © [Juan Soto](https://juansoto.me)

---
_Source: https://npm.io/package/fugot · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
