parrot-module-url v0.12.16
Parrot URL
(https://badges.gitter.im/Join Chat.svg)
URL Management with support for different environments (testing, production, development,...).
Remember use with AJAX module for better experience.
Browsers Compatibility
Install
bower install parrot-module-url --saveGet Started
The module parrot.url provides you everything you need for URL management. For do this:
- Extend
parrotnamespace. - Add new
parrot.endpointnamespace. - Add new
parrot.urlnamespace.
Documentation
parrot
In the parrot namespace, add the following methods:
.environment
It returns the environment that you are using at this moment.
parrot.environment
# => 'development'The default environment is development.
parrot.endpoint
The methods that are available in the parrot.endpoint namespace are:
.add(<Object>)
It registers a new endpoint. Object must have:
name : 'development'
url : 'http://localhost:1337'When you register an endpoint it is accesible in the parrot.endpoint namespace:
parrot.endpoint.development()
# => http://localhost:1337.set(<String>)
It sets the default environment of parrot.environment. It's important due to the URLs depend on the URL path registered in the environment.
parrot.environment.set 'production'The methods that are available in parrot.url namespace are:
URL Management makes easier to do ajax or sockets requests with your backend. In order to do it, you need first to register the URLs. Each URL has a different schema, as protocol, path and/or query.
parrot.URL
.add(<Object>)
It registers a new URL. The minimum information you need to check is:
name: 'login'You can specify the same options than ajax options and other options specify of the URL:
path : 'user/find'
query : ['sort','id asc']Remember that in a URL Object the url is equal to:
<endpoint URL>/[url.path]/[url.query]Now, the URL is available in the parrot.url namespace:
parrot.url.login()
# => { method: 'GET', protocol: 'http', path: 'user/login', query: null }If you want update a value, you can provide an argument when you call the method. For example, if you want to login you need to send the user information to the server:
user = username: 'kiko', password: 'nerd'
parrot.url.login send: userLicense
MIT © ParrotJS
11 years ago