https://github.com/pablopunk/auth-fetch
Fetch JSON with a Bearer token
https://github.com/pablopunk/auth-fetch
Last synced: 11 months ago
JSON representation
Fetch JSON with a Bearer token
- Host: GitHub
- URL: https://github.com/pablopunk/auth-fetch
- Owner: pablopunk
- Created: 2021-02-12T16:45:28.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-02-12T16:47:37.000Z (over 5 years ago)
- Last Synced: 2025-06-30T08:59:34.861Z (12 months ago)
- Language: JavaScript
- Homepage:
- Size: 17.6 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# auth-fetch
Fetch JSON with a Bearer token
## Install
```sh
npm install auth-fetch
```
## Usage
When you create an instance, you can use every http method and it will automatically fill
the API url and the Bearer token. Also, it will request the data as `application/json`,
and it will unwrap the json result for you (equivalent to `fetch(url).then(r => r.json())`)
```js
import AuthFetch from 'auth-fetch'
const fetch = new AuthFetch('/api/users', 'secret-token')
await fetch.get().then(users => console.log(users))
await fetch.put({id: 2, name: 'pablo'})
await fetch.put({id: 2, name: 'pablo varela'})
await fetch.delete({id: 2})
```
## License
MIT
## Author
|  |
| --------------------------------- |
| [Pablo Varela](https://pablopunk.com) |