All Projects → simov → Purest

simov / Purest

Licence: apache-2.0
REST API Client Library

Programming Languages

javascript
184084 projects - #8 most used programming language
js
455 projects

Projects that are alternatives of or similar to Purest

Simple Web Server
A very simple, fast, multithreaded, platform independent HTTP and HTTPS server and client library implemented using C++11 and Boost.Asio. Created to be an easy way to make REST resources available from C++ applications.
Stars: ✭ 2,261 (+404.69%)
Mutual labels:  rest, https, client
Restrequest4delphi
API to consume REST services written in any programming language with support to Lazarus and Delphi
Stars: ✭ 162 (-63.84%)
Mutual labels:  api, rest, client
Https
Secure HTTP client with SSL pinning for Nativescript - iOS/Android
Stars: ✭ 45 (-89.96%)
Mutual labels:  api, https, client
Verb
Organize and send HTTP requests from Emacs
Stars: ✭ 205 (-54.24%)
Mutual labels:  api, rest, client
Flickr Sdk
Almost certainly the best Flickr API client in the world for node and the browser
Stars: ✭ 104 (-76.79%)
Mutual labels:  api, rest, client
Httpie
As easy as /aitch-tee-tee-pie/ 🥧 Modern, user-friendly command-line HTTP client for the API era. JSON support, colors, sessions, downloads, plugins & more. https://twitter.com/httpie
Stars: ✭ 53,052 (+11741.96%)
Mutual labels:  api, rest, client
React Refetch
A simple, declarative, and composable way to fetch data for React components
Stars: ✭ 3,418 (+662.95%)
Mutual labels:  api, rest
Fakerest
Patch fetch/XMLHttpRequest to fake a REST API server in the browser, based on JSON data.
Stars: ✭ 350 (-21.87%)
Mutual labels:  rest, client
Jsonplaceholder
A simple online fake REST API server
Stars: ✭ 4,377 (+877.01%)
Mutual labels:  api, rest
Vuex Rest Api
A utility to simplify the use of REST APIs with Vuex
Stars: ✭ 365 (-18.53%)
Mutual labels:  api, rest
Api
HeadHunter API: документация и библиотеки
Stars: ✭ 324 (-27.68%)
Mutual labels:  api, rest
Thehivedocs
Documentation of TheHive
Stars: ✭ 353 (-21.21%)
Mutual labels:  api, rest
Crudl
CRUDL is a backend agnostic REST and GraphQL based admin interface
Stars: ✭ 438 (-2.23%)
Mutual labels:  api, rest
Pode
Pode is a Cross-Platform PowerShell web framework for creating REST APIs, Web Sites, and TCP/SMTP servers
Stars: ✭ 329 (-26.56%)
Mutual labels:  rest, https
Airtable Python Wrapper
Python Airtable Client Wrapper
Stars: ✭ 328 (-26.79%)
Mutual labels:  api, client
Loopback Next
LoopBack makes it easy to build modern API applications that require complex integrations.
Stars: ✭ 3,972 (+786.61%)
Mutual labels:  api, rest
Zoonavigator
Web-based ZooKeeper UI / editor / browser
Stars: ✭ 326 (-27.23%)
Mutual labels:  api, rest
Service Proxy
API gateway for REST and SOAP written in Java.
Stars: ✭ 355 (-20.76%)
Mutual labels:  api, rest
Bitcoin Core
A modern Bitcoin Core REST and RPC client.
Stars: ✭ 379 (-15.4%)
Mutual labels:  rest, client
Django Api Domains
A pragmatic styleguide for Django API Projects
Stars: ✭ 365 (-18.53%)
Mutual labels:  api, rest

Purest

npm-version travis-ci coveralls-status

REST API Client Library

var purest = require('purest')
var google = purest({provider: 'google'})

await google
  .query('youtube')
  .select('channels')
  .where({forUsername: 'GitHub'})
  .auth(token)
  .request()

Table of Contents

This is Purest v4, for older releases take a look at v3 and v2


Introduction

Purest is a tool for creating expressive REST API clients

Default Endpoint

Here is a basic configuration for Google:

{
  "google": {
    "default": {
      "origin": "https://www.googleapis.com",
      "path": "{path}",
      "headers": {
        "authorization": "Bearer {auth}"
      }
    }
  }
}

With it we can instantiate that provider:

var google = purest({provider: 'google', config})

Then we can request some data from YouTube:

var {res, body} = await google
  .get('youtube/v3/channels')
  .qs({forUsername: 'GitHub'})
  .auth(token)
  .request()

Explicit Endpoint

We can define explicit endpoint for accessing YouTube:

{
  "google": {
    "default": {
      "origin": "https://www.googleapis.com",
      "path": "{path}",
      "headers": {
        "authorization": "Bearer {auth}"
      }
    },
    "youtube": {
      "origin": "https://www.googleapis.com",
      "path": "youtube/{version}/{path}",
      "version": "v3",
      "headers": {
        "authorization": "Bearer {auth}"
      }
    }
  }
}

Then request the same data from YouTube:

var {res, body} = await google('youtube')
  .get('channels')
  .qs({forUsername: 'GitHub'})
  .auth(token)
  .request()

Defaults

Every method in Purest can also be passed as an option:

var google = purest({provider: 'google', config,
  defaults: {auth: token}
})

Then we no longer need to set the access token for every request:

var {res, body} = await google('youtube')
  .get('channels')
  .qs({forUsername: 'GitHub'})
  .request()

Method Aliases

But what if we want to make our API more expressive? What if we want to make it our own:

var google = purest({provider: 'google', config,
  defaults: {auth: token},
  methods: {get: ['select'], qs: ['where']}
})

Yes we can:

var {res, body} = await google('youtube')
  .select('channels')
  .where({forUsername: 'GitHub'})
  .request()

Purest Options

Purest is a flexible tool for abstracting out REST APIs

var google = purest({config: {}, provider: 'google', defaults: {}, methods: {}})
Key Type Description
config {} Provider configuration to use
provider '' Provider name to initialize from the list of providers found in config
defaults {} Any supported configuration option set by default, see below
methods {} List of methods and their aliases to use with this instance

Request Options

Purest is built on top of a powerful HTTP Client

URL Options

Option Description
origin The protocol and domain part of the URL, can contain {subdomain} token
path The path part of the URL, can contain {version}, {path} and {type} tokens
subdomain Subdomain part of the URL to replace in origin
version Version string to replace in path
type Type string to replace in path, typically json or xml

HTTP Methods

All HTTP methods get head post put patch options delete trace connect accept a string to replace the {path} configuration token with, or absolute URL to replace the entire url.

Request Options

Option Type Description
method 'string' Request method, implicitly set if one of the above HTTP Methods is used
url 'string' url object Absolute URL, automatically constructed if the URL Options above are being used, or absolute URL is passed to any of the HTTP Methods above
proxy 'string' url object Proxy URL; for HTTPS you have to use tunneling agent instead
qs {object} 'string' URL querystring
headers {object} Request headers
form {object} 'string' application/x-www-form-urlencoded request body
json {object} 'string' JSON encoded request body
multipart {object} [array] multipart/form-data as object or multipart/related as array request body using request-multipart
body 'string' Buffer Stream Raw request body
auth 'string' ['string', 'string'] {user, pass} String or array of strings to replace the {auth} configuration token with, or Basic authorization as object
oauth {object} OAuth 1.0a authorization using request-oauth
encoding 'string' Response body encoding
redirect {object} HTTP redirect configuration
timeout number Request timeout in milliseconds
agent Agent HTTP agent

Response Options

request

  • buffers the response body
  • decompresses gzip and deflate encoded bodies with valid content-encoding header
  • converts the response body to string using utf8 encoding by default
  • tries to parse JSON and querystring encoded bodies with valid content-type header

Returns either String or Object.

buffer

  • buffers the response body
  • decompresses gzip and deflate encoded bodies with valid content-encoding header

Returns Buffer.

stream

Returns the response Stream.

Node Core Options

Any other HTTP request option not explicitly exposed in Purest can be passed using any of the response methods:

await google.request({socketPath: ''})
await google.buffer({socketPath: ''})
await google.stream({socketPath: ''})

Endpoint

The explicit endpoint configuration can be accessed in various ways:

// as argument to the Purest instance
await google('youtube')
// using the option name
await google.endpoint('youtube')
// or the default method alias defined for it
await google.query('youtube')

Examples

Purest comes with a fancy logger

npm i --save-dev request-logs
DEBUG=req,res,body,json node examples/file-name.js 'example name'
Category Topics Providers Examples
OAuth 2.0 Refresh Access Tokens box google twitch Refresh access tokens
OpenID Connect Verify id_token auth0 google microsoft Discover public keys and verify id_token signature
OAuth 1.0a OAuth 1.0a flickr trello twitter Get user profile
Storage Multipart, Streams box dropbox drive Upload files
Storage HTTP Streams box dropbox Stream file from DropBox to Box

Get access tokens using Grant

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].