Skip to content
This repository has been archived by the owner on Apr 6, 2019. It is now read-only.

ivan-94/rest-model

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#REST-model An elegant REST client for Javascript

Install

npm i rest-model

Usage

// import fetch polyfill
import "whatwg-fetch"
import Rest from 'rest-model' 

const api = new Rest('api', '/api/vi')
api.use(async (ctx, next) => {
    console.log('before foo')
    ctx.headers.set('X-Token', 'adad23ezcab8162easd')
    await next()
    console.log('after foo')
})

const Users = new Rest('User', '/users')
User
  .use(async (ctx, next) => {
    console.log('before bar')
    await next()
    console.log('after bar')
  })
  .post('create', '/')
  .get('all', '/')
  .get('types', '/types')
  .get('/:id')

const $ = api.nest(Users)
  .model()

$.Users.get({id: 1})  // => GET /api/v1/users/1
$.Users.all()         // => GET /api/v1/users/
$.Users.types()       // => GET /api/v1/users/types
$.Users.create(null, {name: 'foo', age: 12}) // => POST /api/v1/users/

// hooks
$.Users.all()        // => before foo
                     // => before bar
                     // => after bar
                     // => after foo

API

About

An elegance REST client base on Fetch

Resources

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published