0.2.12 • Published 7 years ago

legible v0.2.12

Weekly downloads
3
License
ISC
Repository
github
Last release
7 years ago

CircleCI
All Contributors

Legible

See my blog post on why I made this

Proof of concept at making http requests easier to work with in JS / Node. This wraps the fetch api.

npm install legible --save

A request library using template literals. Making requests has never been so straight forward! Make it easy for users to adopt your api, document it using this library, and everyone will understand making requests.

Example

import request from 'legible'

async function TestRequest() {
  let body = {
    email: 'test@test.com',
    password: 'secret'
  }

  let response = await request`
    url: https://api.myapp.com/register
    method: POST
    body: ${body}
    headers: ${{
      Authorization: 'Bearer: token'
    }}
  `
}

Partial Requests

New in 0.2.0!

Using template strings, we can pull out variables easily and keep requests as legible as possible. Imagine splitting out your code like this using api libraries that include requests like so:

import { partial } from 'legible'

const twitter = {
  register: partial`
    url: https://api.twitter.com/register,
    method: POST
  `
}

twitter.register`
  body: ${{
    email: 'test@test.com',
    password: 'Tester'
  }}
`

Middleware

Coming Soon The following isn't implemented yet.

import request from 'legible'

request.middleware({
  headers: {
    Authorization: `Bearer: ${localStorage.getItem('token')}`
  },
  after({ headers }) {
    localStorage.setItem('token', headers.Authorization)
  }
})

Contributors

Thanks goes to these wonderful people (emoji key):

Zach Silveira💻 📖 👀Ray Gesualdo💻 📖

This project follows the all-contributors specification. Contributions of any kind welcome!

0.2.12

7 years ago

0.2.11

7 years ago

0.2.10

7 years ago

0.2.9

7 years ago

0.2.8

7 years ago

0.2.7

7 years ago

0.2.6

7 years ago

0.2.5

7 years ago

0.2.4

7 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago