# highwire

> A high level HTTP client

Latest version **1.1.6** (published 2016-07-01) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.6 |
| Published | 2016-07-01 |
| First published | 2016-04-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 3 |
| Author | kurtiskemple@gmail.com |
| Maintainers | kkemple |
| Keywords | http, bluebird, promises, requests, network, api, client, request, superagent, highwire, network, requests |

## Links

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

## Dependencies (1)

- [superagent](https://npm.io/package/superagent.md) ^2.0.0

## 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.1.6 (latest) — 2016-07-01
- 1.1.5 — 2016-07-01
- 1.1.4 — 2016-07-01
- 1.1.3 — 2016-04-17
- 1.1.2 — 2016-04-17
- 1.0.2 — 2016-04-16
- 1.0.1 — 2016-04-16
- 1.0.0 — 2016-04-16
- 0.0.1 — 2016-04-16

## README

# Highwire

High level HTTP methods that are easy to build upon.

[![Code Climate](https://codeclimate.com/github/kkemple/highwire/badges/gpa.svg)](https://codeclimate.com/github/kkemple/highwire)
[![Test Coverage](https://codeclimate.com/github/kkemple/highwire/badges/coverage.svg)](https://codeclimate.com/github/kkemple/highwire/coverage)
[![Issue Count](https://codeclimate.com/github/kkemple/highwire/badges/issue_count.svg)](https://codeclimate.com/github/kkemple/highwire)
[![Circle CI](https://circleci.com/gh/kkemple/highwire.svg?style=svg)](https://circleci.com/gh/kkemple/highwire)

## Reasoning
[Superagent](https://visionmedia.github.io/superagent/) is a fantastic module, but I find that I generally need to wrap it up for use in a more functional approach. `Highwire` provides this functional approach through simple HTTP methods that work great for building complex network layers, or just to make syncing your React components easier. They are meant to be wrapped in higher order functions to build complex network logic.

## API
Highwire exposes an object with RESTful HTTP methods. Those methods are:

### get(url [, options: { headers, query } ])

  - url: full url of request
  - options:
    - headers: object of headers to attatch to request
    - query: object of query parameters to attach to request (DO NOT USE: if url contains query params)
    - timeout: cancel request after specified timeout (throws Error)

```javascript
import { get } from 'highwire'
import { User } from './models'

const headers = { authorization: 'token <token>' }
const query = { sortOrder: 'desc' }
const timeout = 3000

get('/users', { headers, query, timeout })
  .then((response) => response.body)
  .then((body) => JSON.parse(body))
  .then((users) => console.log(users))
  .catch((err) => console.log(err))
```

### post(url, data [, options: { headers, query } ])

  - url: full url of request
  - data: body to send with request
  - options:
    - headers: object of headers to attatch to request
    - query: object of query parameters to attach to request (DO NOT USE: if url contains query params)
    - timeout: cancel request after specified timeout (throws Error)
    - progress: function that is called on progress event of request; returns: `{ direction: string, lengthComputable: boolean, loaded: number, total: number }`

```javascript
import { post } from 'highwire'
import { User } from './models'

const headers = { authorization: 'token <token>' }
const timeout = 3000
const progress = (event) => console.log(event.loaded))
const user = new User({ name: 'highwire' })

post('/users', user.toJSON(), { headers, timeout, progress })
  .then((response) => response.body)
  .then((body) => JSON.parse(body))
  .then((user) => console.log(user))
  .catch((err) => console.log(err))
```

### put(url, data [, options: { headers, query } ])

  - url: full url of request
  - data: body to send with request
  - options:
    - headers: object of headers to attatch to request
    - query: object of query parameters to attach to request (DO NOT USE: if url contains query params)
    - timeout: cancel request after specified timeout (throws Error)

```javascript
import { put } from 'highwire'
import { User } from './models'

const headers = { authorization: 'token <token>' }
const timeout = 3000

User.find({ name: 'highwire' })
  .then((user) => user.addScope('some-action'))
  .then((user) => put(`/users/${user.id}`, user.toJSON(), { headers, timeout }))
  .then((response) => response.body)
  .then((body) => JSON.parse(body))
  .then((user) => console.log(user))
  .catch((err) => console.log(err))
```

### patch(url, data [, options: { headers, query } ])

  - url: full url of request
  - data: body to send with request
  - options:
    - headers: object of headers to attatch to request
    - query: object of query parameters to attach to request (DO NOT USE: if url contains query params)
    - timeout: cancel request after specified timeout (throws Error)

```javascript
import { patch } from 'highwire'
import { User } from './models'

const headers = { authorization: 'token <token>' }
const timeout = 3000

User.find({ name: 'highwire' })
  .then((user) => user.addScope('some-action'))
  .then((user) => patch(`/users/${user.id}`, user.toJSON(), { headers, timeout }))
  .then((response) => response.body)
  .then((body) => JSON.parse(body))
  .then((user) => console.log(user))
  .catch((err) => console.log(err))
```

### del(url, [, options: { headers, query } ])

  - url: full url of request
  - options:
    - headers: object of headers to attatch to request
    - query: object of query parameters to attach to request (DO NOT USE: if url contains query params)
    - timeout: cancel request after specified timeout (throws Error)

```javascript
import { del } from 'highwire'
import { User } from './models'

const headers = { authorization: 'token <token>' }
const timeout = 3000

User.find({ name: 'highwire' })
  .then((user) => del(`/users/${user.id}`, { headers, timeout }))
  .then(() => console.log('user deleted'))
  .catch((err) => console.log(err))
```

### multipart(url, { meta: fields, attachments } [, options: { headers, query, progress }])

- url: full url of request
- meta:
  - fields[[name, value]] any form fields to attach to request
  - attachments[[name, path, filename]]: any attachments to attach to request
    - [superagent docs](https://visionmedia.github.io/superagent/#multipart-requests)
- options:
  - headers: object of headers to attatch to request
  - query: object of query parameters to attach to request (DO NOT USE: if url contains query params)
  - timeout: cancel request after specified timeout (throws Error)
  - progress: function that is called on progress event of request; returns: `{ direction: string, lengthComputable: boolean, loaded: number, total: number }`

```javascript
const attachments = [
  ['profile', './tmp/profile.jpg'],
]
const progress = (event) => console.log(event)
const timeout = 5000

User.find({ name: 'highwire' })
  .then((user) =>
    multipart(
      `/users/${user.id}/profile`,
      { attachments },
      { progress, timeout },
    )
  .then((response) => JSON.parse(response.body))
  .then((data) => console.log(data))
  .catch((err) => console.log(err))
```

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