https://github.com/legitcode/legible
the cleanest way to make http requests in js / node
https://github.com/legitcode/legible
fetch fetch-api js node request
Last synced: 7 months ago
JSON representation
the cleanest way to make http requests in js / node
- Host: GitHub
- URL: https://github.com/legitcode/legible
- Owner: Legitcode
- Created: 2016-12-06T01:24:18.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-05-25T20:31:06.000Z (about 8 years ago)
- Last Synced: 2024-12-01T00:07:38.137Z (7 months ago)
- Topics: fetch, fetch-api, js, node, request
- Language: JavaScript
- Size: 33.2 KB
- Stars: 47
- Watchers: 7
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
Awesome Lists containing this project
README
[](https://circleci.com/gh/Legitcode/legible)
[](#contributors)
## Legible[See my blog post on why I made this](https://zach.codes/human-readable-ajax-requests/)
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
```js
import request from 'legible'async function TestRequest() {
let body = {
email: '[email protected]',
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:
```js
import { partial } from 'legible'const twitter = {
register: partial`
url: https://api.twitter.com/register,
method: POST
`
}twitter.register`
body: ${{
email: '[email protected]',
password: 'Tester'
}}
`
```### Middleware
**Coming Soon** The following isn't implemented yet.
```js
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](https://github.com/kentcdodds/all-contributors#emoji-key)):
| [
Zach Silveira](http://reactjsnews.com)
[💻](https://github.com/Legitcode/legible/commits?author=zackify) [📖](https://github.com/Legitcode/legible/commits?author=zackify) 👀 | [
Ray Gesualdo](https://github.com/raygesualdo)
[💻](https://github.com/Legitcode/legible/commits?author=raygesualdo) [📖](https://github.com/Legitcode/legible/commits?author=raygesualdo) |
| :---: | :---: |This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!