1.0.0 • Published 10 years ago
urlinate v1.0.0
Urlinate
Adds data to a URL
var newUrl = urlinate(url, data)
Adds data to a URL. As syntax sugar for recursion, if the data provided contains an object with a key === '$', the value at that key will be considered an array of arguments to pass to urlinate to obtain a string which will replace said object.
- url (string) - Anything you can pass to Node's url.parse
- data (object) - The data to add to the URL
- returns (string) newUrl - the original url but with specified data encoded in the
dquery parameter
var urlinator = require('urlinator')
urlinate('cachinate.io', {
asset: {
$: ['imaginate.io', {
input: 'imgs.io/a.jpg'
}]
}
})
// cachinate.io?asset=imaginate.io%3Finput%3Dimgs.io%252Fa.jpgWhy?
This makes it easy to create an ecosystem of chainable HTTP GET APIs. This is useful if, for example, a browser is launching a request for you (from an image tag or css instruction) but you still want to use your API.
Services using this kind of API
Example with chaining and nesting
1.0.0
10 years ago