项目作者: dbtek

项目描述 :
A full featured Rest API client around window.fetch to provide idiomatic interaction (under 1kB)
高级语言: JavaScript
项目地址: git://github.com/dbtek/fresource.git
创建时间: 2018-11-07T13:45:16Z
项目社区:https://github.com/dbtek/fresource

开源协议:MIT License

下载



f·resource




Test Coverage



Standard





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

Install

With npm:

  1. $ npm i fresource --save

Via CDN:

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

Usage

  1. var fresource = require('fresource')
  2. var Users = fresource('/api/users/:id?sort=:sort')
  3. Users.get({ sort: 'name' }) // will fetch /api/users?sort=name
  4. .then(result => {
  5. var users = result
  6. })
  7. Users.get({ id: 1 }) // will fetch /api/users/1
  8. .then(result => {
  9. var user = result
  10. })

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