UNPKG

resturlify

Version:
54 lines (41 loc) 816 B
# RestUrlify Consistently Generate Rest URLs ## Why? I wrote this to help transition my team from an RPC-each-call-a-snowflake tendency to REST. ## Use Anywhere This library works in the client and on the server. ## Install ```` bower install resturlify ```` Or ```` npm install resturlify ```` ### Examples #### Constructor ```javascript var urlTools = new RestUrlify("http://www.web.com/api"); ``` #### Simple ```javascript urlTools.buildUrl() ``` Returns: http://www.web.com/api #### With Params ```javascript urlTools.buildUrl({ resource: 'resource', query: {id : 1} }) ``` Returns: http://www.web.com/api/resource?id=1 #### Custom Methods ```javascript urlTools.buildUrl({ resource: 'resource', id: 1, customMethod: 'approve' }) ``` Returns: http://www.web.com/api/resource/1/approve