You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

fresource

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fresource

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

0.8.0
latest
Source
npmnpm
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

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.delete(params)
Sends a DELETE request with given parameters.
Returns promise.

Author

Ismail Demirbilek @dbtek

License

MIT

Keywords

rest

FAQs

Package last updated on 05 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts