https://github.com/dbtek/fresource
A full featured Rest API client around window.fetch to provide idiomatic interaction (under 1kB)
https://github.com/dbtek/fresource
ajax api client fetch resource rest tiny
Last synced: 7 months ago
JSON representation
A full featured Rest API client around window.fetch to provide idiomatic interaction (under 1kB)
- Host: GitHub
- URL: https://github.com/dbtek/fresource
- Owner: dbtek
- License: mit
- Created: 2018-11-07T13:45:16.000Z (about 7 years ago)
- Default Branch: main
- Last Pushed: 2024-01-05T15:41:43.000Z (almost 2 years ago)
- Last Synced: 2024-08-08T21:53:02.924Z (over 1 year ago)
- Topics: ajax, api, client, fetch, resource, rest, tiny
- Language: JavaScript
- Size: 256 KB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
All in one client for your REST API under 1kB.
## Install
With npm:
```bash
$ npm i fresource --save
```
Via CDN:
```html
```
## Usage
```js
var fresource = require('fresource')
var Users = fresource('/api/users/:id?sort=:sort')
Users.get({ sort: 'name' }) // will fetch /api/users?sort=name
.then(result => {
var users = result
})
Users.get({ id: 1 }) // will fetch /api/users/1
.then(result => {
var user = result
})
```
## API
**Collection = fresource(path)**
Initialize a resource with a path / url. Path should include all path / query parameter variables like `:key`.
**Collection.get(params)**
Fetches a `GET` request with given parameters.
Returns promise.
**Collection.save(params)**
Sends a `POST` request with given parameters. Residual parameters that are not used in url will be posted in body.
Returns promise.
**Collection.update(params)**
Sends a `PUT` request with given parameters. Residual parameters that are not used in url will be posted in body.
Returns promise.
**Collection.patch(params)**
Sends a `PATCH` request with given parameters. Residual parameters that are not used in url will be posted in body.
Returns promise.
**Collection.delete(params)**
Sends a `DELETE` request with given parameters.
Returns promise.
## Author
Ismail Demirbilek [@dbtek](https://twitter.com/dbtek)
## License
MIT