All Projects → lukeed → Httpie

lukeed / Httpie

Licence: mit
A Node.js HTTP client as easy as pie! 🥧

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Httpie

Fetch
Asynchronous HTTP client with promises.
Stars: ✭ 29 (-94.85%)
Mutual labels:  promises, http-client
Restclient
🦄 Simple HTTP and REST client for Unity based on Promises, also supports Callbacks! 🎮
Stars: ✭ 675 (+19.89%)
Mutual labels:  promises, http-client
Async Http Client
HTTP client library built on SwiftNIO
Stars: ✭ 414 (-26.47%)
Mutual labels:  http-client
Apfree wifidog
A hight performance and lightweight captive portal solution for HTTP(s)
Stars: ✭ 519 (-7.82%)
Mutual labels:  http-client
Phin
Node HTTP client
Stars: ✭ 449 (-20.25%)
Mutual labels:  http-client
Resty
Simple HTTP and REST client library for Go
Stars: ✭ 5,368 (+853.46%)
Mutual labels:  http-client
Asyncro
⛵️ Beautiful Array utilities for ESnext async/await ~
Stars: ✭ 487 (-13.5%)
Mutual labels:  promises
Malibu
🏄 Malibu is a networking library built on promises
Stars: ✭ 409 (-27.35%)
Mutual labels:  promises
Tray
Browser plugin for sending documents and raw commands to a printer or attached device.
Stars: ✭ 543 (-3.55%)
Mutual labels:  promises
Guzzle
Guzzle, an extensible PHP HTTP client
Stars: ✭ 21,384 (+3698.22%)
Mutual labels:  http-client
Http
Event-driven, streaming HTTP client and server implementation for ReactPHP.
Stars: ✭ 507 (-9.95%)
Mutual labels:  http-client
Node Libcurl
libcurl bindings for Node.js
Stars: ✭ 447 (-20.6%)
Mutual labels:  http-client
Kohttp
Kotlin DSL http client
Stars: ✭ 436 (-22.56%)
Mutual labels:  http-client
Aspida
TypeScript friendly HTTP client wrapper for the browser and node.js.
Stars: ✭ 490 (-12.97%)
Mutual labels:  http-client
Ky Universal
Use Ky in both Node.js and browsers
Stars: ✭ 421 (-25.22%)
Mutual labels:  http-client
Lithium
Easy to use C++17 HTTP Server with no compromise on performances. https://matt-42.github.io/lithium
Stars: ✭ 523 (-7.1%)
Mutual labels:  http-client
Vial Http
Simple http rest tool for vim
Stars: ✭ 412 (-26.82%)
Mutual labels:  http-client
Httpdirfs
A filesystem which allows you to mount HTTP directory listings, with a permanent cache. Now with Airsonic / Subsonic support!
Stars: ✭ 443 (-21.31%)
Mutual labels:  http-client
Requests
Convenient http client for java, inspired by python request module
Stars: ✭ 459 (-18.47%)
Mutual labels:  http-client
Http Client
Async HTTP/1.1+2 client for PHP based on Amp.
Stars: ✭ 553 (-1.78%)
Mutual labels:  http-client
httpie
A Node.js HTTP client as easy as pie!

Features

  • Promise- based HTTP requestor
  • Works with HTTP and HTTPS protocols
  • Automatically handles JSON requests and responses
  • Extremely lightweight with no dependencies 678 bytes!
  • Includes aliases for common HTTP verbs: get, post, put, patch, and del

Additionally, this module is delivered as:

Install

$ npm install --save httpie

Usage

Note: The async syntax is for demo purposes – you may use Promises in a Node 6.x environment too!

import { get, post } from 'httpie';

try {
  const { data } = await get('https://pokeapi.co/api/v2/pokemon/1');

  // Demo: Endpoint will echo what we've sent
  const res = await post('https://jsonplaceholder.typicode.com/posts', {
    body: {
      id: data.id,
      name: data.name,
      number: data.order,
      moves: data.moves.slice(0, 6)
    }
  });

  console.log(res.statusCode); //=> 201
  console.log(res.data); //=> { id: 1, name: 'bulbasaur', number: 1, moves: [{...}, {...}] }
} catch (err) {
  console.error('Error!', err.statusCode, err.message);
  console.error('~> headers:', err.headers);
  console.error('~> data:', err.data);
}

API

send(method, url, opts={})

Returns: Promise

Any httpie.send request (and its aliases) will always return a Promise.

If the response's statusCode is 400 or above, this Promise will reject with a formatted error – see Error Handling. Otherwise, the Promise will resolve with the full ClientRequest stream.

The resolved response will receive a new data key, which will contain the response's full payload. Should the response return JSON content, then httpie will parse it and the res.data value will be the resulting JSON object!

method

Type: String

The HTTP method name – it must be uppercase!

url

Type: String or URL

If url is a string, it is automatically parsed with url.parse() into an object.

opts.body

Type: Mixed
Default: undefined

The request's body, can be of any type!

Any non-Buffer objects will be converted into a JSON string and the appropriate Content-Type header will be attached.

Additionally, httpie will always set a value for the Content-Length header!

opts.headers

Type: Object
Default: {}

The custom headers to send with your request.

opts.redirect

Type: Boolean
Default: true

Whether or not redirect responses should be followed automatically.

Note: This may only happen with a 3xx status and if the response had a Location header.

opts.reviver

Type: Function
Default: undefined

An optional function that's passed directly to JSON.parse, allowing you transform aspects of the response data before the httpie request resolves.

Note: This will only run if httpie detects that JSON is contained in the response!

get(url, opts={})

Alias for send('GET', url, opts).

post(url, opts={})

Alias for send('POST', url, opts).

put(url, opts={})

Alias for send('PUT', url, opts).

patch(url, opts={})

Alias for send('PATCH', url, opts).

del(url, opts={})

Alias for send('DELETE', url, opts).

Error Handling

All responses with statusCode >= 400 will result in a rejected httpie request. When this occurs, an Error instance is formatted with complete information:

  • err.messageString – Identical to err.statusMessage;
  • err.statusMessageString – The response's statusMessage value;
  • err.statusCodeNumber – The response's statusCode value;
  • err.headersObject – The response's headers object;
  • err.dataMixed – The response's payload;

Important: The error's data property may also be parsed to a JSON object, according to the response's headers.

import { get } from 'httpie';

get('https://example.com/404').catch(err => {
  console.error(`(${err.statusCode}) ${err.message}`)
  console.error(err.headers['content-type']);
  console.error(`~> ${err.data}`);
});
//=> "(404) Not Found"
//=> "text/html; charset=UTF-8"
//=> ~> <?xml version="1.0" encoding="iso-8859-1"?>\n<!DOCTYPE html ...</body>\n</html>

License

MIT © Luke Edwards

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].