resource-oriented-request

0.1.7 • Public • Published

Resource-oriented Request

Resource-oriented request

Usage

yarn add resource-oriented-request

example

Basic

import API,{baseURL} from 'resource-oriented-request'
@baseURL('http://localhost:3000')
class Base extends API {}
 
class Post extends Base {
  static prefix = 'admin'
 
  static header = {
    'X-Tags': 'test'
  }
 
  static archives() {
    return this.get('archives')
  }
}
 
await Post.get()
// => GET http://localhost:3000/posts
 
await Post.getById(1)
// => GET http://localhost:3000/posts/1
 
await Post.archives()
// => GET http://localhost:3000/posts/archives
 
await Post.post({
  title: 'test title',
  context: 'long long long context',
})
// => POST http://localhost:3000/posts
// Form data: {title: 'test title',context: 'long long long context'})

Prefix

class Post extends Base {
  static prefix = 'admin'
}
 
await Post.get()
// => GET http://localhost:3000/admin/posts
await Post.getById(1)
// => GET http://localhost:3000/admin/posts/1
await Post.post({
  title: 'test title',
  context: 'long long long context',
})
// => POST http://localhost:3000/admin/posts
// form data: {title: 'test title',context: 'long long long context'})

Headers

class Post extends Base {
  static headers = {
    'X-Tags': 'test,boom'
  }
}
async () => {
  const await Post.get() 
  // => GET http://localhost:3000/admin/posts
  // Requset Header:
  // ...
  // X-Tags: test,boom
  // ...
}

API

docs/api.md

Readme

Keywords

Package Sidebar

Install

npm i resource-oriented-request

Weekly Downloads

2

Version

0.1.7

License

BSD-2-Clause

Unpacked Size

238 kB

Total Files

11

Last publish

Collaborators

  • dov-yih