RESTed Resources
RESTed Resources is a client-side REST-based API layer for your resources. Conceptually similar to ngResource
, it
handles http requests and URL building to give you simple, consistent logic.
Resources automatically generate URLs based on their hierarchy. Requests are managed by superagent and results/errors are handled via Promises.
Installation
npm install rested-resources --save
- or for yarn users:
yarn add rested-resources
Usage
While RESTed Resources works as a client-side library, it's built as an NPM module with the assumption you're using webpack or a related library to compile your application.
Examples below are written with some ES6, which will require babel to transpile.
Import the resource classes:
;
While you can export resource classes directly, you'll likely want to use a factory to help setup relationships.
-- studentjs {} -- studentsjs {} -- coursejs:;; {} { let resource = data; resource; resource; return resource;}
You now have everything needed to interact with these resources.
Querying for all students in a course:
var course = courseId: 'history-101' ; // performs: GET /courses/history-101/studentscoursestudents;
Query for a specific student's course data:
var course = courseId: 'history-101' ;var student = studentId: 1234 ; // performs: GET /courses/history-101/students/1234student;
Create a new student record:
var student = name: 'Kermit' ; // performs: POST /studentsstudent;