urlinate

1.0.0 • Public • Published

Urlinate

Adds data to a URL

Build Status js-standard-style npm version Coverage Status

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 d query 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.jpg

Why?

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

Readme

Keywords

Package Sidebar

Install

npm i urlinate

Weekly Downloads

2

Version

1.0.0

License

ISC

Last publish

Collaborators

  • vigour-io