can-make-rest

0.1.4 • Public • Published

can-make-rest

Build Status Greenkeeper badge

Make restful urls and methods from a resource.

makeRest( resourceUrl[, uniqueProperty])

Provide it an "items" resource url and the unique property name and it returns an object with CRUD HTTP methods and templated urls.

makeRest( "/todos", "ID" ); //=> {
//    getData: {method:"GET", url: "/todos/{ID}"},
//    getListData: {method:"GET", url: "/todos"},
//    createData: {method:"POST", url: "/todos"},
//    updateData: {method:"PUT", url: "/todos/{ID}"},
//    destroyData: {method:"DELETE", url: "/todos/{ID}"}
//  }

If a templated "item" resource URL is provided, it will be able to infer the unique property name.

makeRest( "/todos/{_id}" ); //=> {
//    getData: {method:"GET", url: "/todos/{_id}"},
//    getListData: {method:"GET", url: "/todos"},
//    createData: {method:"POST", url: "/todos"},
//    updateData: {method:"PUT", url: "/todos/{_id}"},
//    destroyData: {method:"DELETE", url: "/todos/{_id}"}
//  }

Readme

Keywords

Package Sidebar

Install

npm i can-make-rest

Homepage

canjs.com

Weekly Downloads

2,898

Version

0.1.4

License

MIT

Unpacked Size

11.3 kB

Total Files

14

Last publish

Collaborators

  • cherif_b
  • christopherjbaker
  • justinbmeyer
  • phillipskevin