JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q44976F
  • License MIT

A full featured Rest API client around window.fetch to provide idiomatic interaction.

Package Exports

  • fresource

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (fresource) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

fresource

Build Status Test Coverage Standard

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

Install

With npm:

$ npm i fresource

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 => {
    user = result
  })

Users.get({ id: 1 }) // will fetch /api/users/1
  .then(result => {
    user = result
  })

API

resource = fresource(path)
Initialize a resource with a path / url.

resource.get(params)
Fires a GET request with given parameters. Rewrites all path / query variables (like: :key) with properties of params object.

resource.post(params)
Fires a POST request with given parameters. Rewrite applies here too. Object with residual properties will be posted as body.

resource.update(params)
Fires a PUT request with given parameters. Rewrite applies here too. Object with residual properties will be posted as body.

resource.delete(params)
Fires a DELETE request with given parameters. Rewrite applies here too.

Author

Ismail Demirbilek @dbtek

License

MIT