Skip to content

A full featured Rest API client around window.fetch to provide idiomatic interaction (under 1kB)

License

Notifications You must be signed in to change notification settings

dbtek/fresource

Repository files navigation

f·resource

Test Coverage Standard

All in one client for your REST API under 1kB.

Install

With npm:

$ npm i fresource --save

Via CDN:

<script src="https://unpkg.com/fresource/dist/fresource.js"></script>

Usage

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

License

MIT

About

A full featured Rest API client around window.fetch to provide idiomatic interaction (under 1kB)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •