Modest Angular module for handling nested REST resources.
With great 'inspiration' from:
bower install --save angular-modest
and include angular-modest.js
as a dependency
Requires the modest
module to be installed
A factory that gives you the ability to create RESTful resources mapped to a JavaScript object.
Supports deeply nested resources.
new Resource(url, defaultParams)
Returns an instance of Resource
Param | Type | Description |
---|---|---|
url | string | A parametrized URL template with parameters prefixed by : as in /user/:username |
defaultParams (opt) | Object, int | Default values for the parametrized URL template. |
resource.getResourceUrl()
Returns the resource url for the current instance
resource.getResourceFor(params)
Returns an instance of the nested Resource
Param | Type | Description |
---|---|---|
params | Object | Default values for the parametrized URL template. |
resource.get(params,queryParameters)
Return an $http object to interact with, making a request to the desired resource.
Param | Type | Description |
---|---|---|
params | Object | Default values for the parametrized URL template. |
queryParameters | Object | Query parameters [WIP] |
resource.VERB(params,payload)
Return an $http object to interact with, making a request to the desired resource.
Param | Type | Description |
---|---|---|
params | Object | Default values for the parametrized URL template. |
payload | Object | Payload to be sent with the request |
See the tests
for more detailed information and use cases.
var user = new Resource( '/users/:userId' );
expect( user.getResourceUrl() ).to.equal( '/users/:userId' );
var user = new Resource( '/users/:userId', {userId:1} );
expect( user.getResourceUrl() ).to.equal( '/users/1' );
var user = new Resource( '/users/:userId', {userId:1} );
user.get() // returns $http with GET request made to /users/1
var user = new Resource( '/users/:userId' );
user.get({userId:2}) // returns $http with GET request made to /users/2
user.get(2) // returns $http with GET request made to /users/2
var userBooks = new Resource( '/users/:userId/books/:bookId' );
userBooks.get({userId:1,bookId:1}); // returns $http with GET request made to /users/1/books/1
var users = new Resource( '/users/:userId' );
users.get() // returns $http with GET request made to /users/
// nested resources
var user1 = new Resource( '/users/:userId/books/:bookId', {userId:1} );
user1.get({bookId:1}); // returns $http with GET request made to /users/1/books/1
user1.books.get({bookId:1}); // returns $http with GET request made to /users/1/books/1
user1.books.get(1); // returns $http with GET request made to /users/1/books/1
- fix query parameters when performing request
- fix parameter duplication when requesting nested resource
To setup the environment
npm install
bower install
......
npm test
The best way to get your changes merged back into core is as follows:
- Clone down your fork
- Create a thoughtfully named topic branch to contain your change
- Hack away
- Add tests and make sure everything still passes by running
npm test
- If you are adding new functionality, document it in the README
- Do not change the version number, we will do that on our end
- If necessary, rebase your commits into logical chunks, without errors
- Push the branch up to GitHub
- Send a pull request for your branch