Giter Club home page Giter Club logo

angular-modest's Introduction

angular-modest

Circle CI Coverage

Modest Angular module for handling nested REST resources.

With great 'inspiration' from:

Installation

bower install --save angular-modest

and include angular-modest.js as a dependency

Module components

Requires the modest module to be installed

Factory

Resource

A factory that gives you the ability to create RESTful resources mapped to a JavaScript object.

Supports deeply nested resources.

API

Constructor

new Resource(url, defaultParams)

Returns an instance of Resource

Arguments

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.

Instance methods

getResourceUrl

resource.getResourceUrl()

Returns the resource url for the current instance

getResourceFor

resource.getResourceFor(params)

Returns an instance of the nested Resource

Arguments

Param Type Description
params Object Default values for the parametrized URL template.

get

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]

post,put,delete,head,patch

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

Examples

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

TODO

  • fix query parameters when performing request
  • fix parameter duplication when requesting nested resource

How to contribute

To setup the environment

npm install
bower install

......

npm test

The best way to get your changes merged back into core is as follows:

  1. Clone down your fork
  2. Create a thoughtfully named topic branch to contain your change
  3. Hack away
  4. Add tests and make sure everything still passes by running npm test
  5. If you are adding new functionality, document it in the README
  6. Do not change the version number, we will do that on our end
  7. If necessary, rebase your commits into logical chunks, without errors
  8. Push the branch up to GitHub
  9. Send a pull request for your branch

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.