Skip to content

jmjuanes/url-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

url-api

npm npm npm

Format and generate the urls for an API service

This package will format all the string patterns used in frameworks like express into full urls like this.

Usage

//Import dependencies 
var url_api = require('url-api');

//Url object 
var url_obj = { protocol: 'https', hostname: 'mywebsite.com' }; 

//Api urls 
var api = { projects: '/projects/:project', home: '/', users: '/users/:user' };

//Simple api
url_api(url_obj, api);
// { 
//   projects: 'https://mywebsite.com/projects/{project}',
//   home: 'https://mywebsite.com/',
//   users: 'https://mywebsite.com/users/{user}' 
// }

//With options
url_api(url_obj, api, { prefix: '{{', suffix: '}}' });
// { 
//   projects: 'https://mywebsite.com/projects/{{project}}',
//   home: 'https://mywebsite.com/',
//   users: 'https://mywebsite.com/users/{{user}}' 
// }

API

url_api(url_obj, api[, opt])

Returns a new object with all the pathnames formatted. This method accepts the following arguments:

  • url_obj: a url object with the API host information.
  • api: an object with all the paths strings of your RESTful API service.
  • opt (optionally): an object with the options:
    • find: a regular expression to find the pattern parameters. Default is set to find the parameters starting with :.
    • prefix: the formatted pattern parameter prefix. Default is {.
    • suffix: the formatted pattern parameter suffix. Default is }.

License

MIT LICENSE © Josemi Juanes.

About

Format and generate the urls for an API service

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published