/nkr_urlbuilder

REST API Url builder

Primary LanguageJavaScriptGNU General Public License v3.0GPL-3.0

REST API URL Builder

Generate the REST API Urls in the front-end with this little code-snippet. Don't write:

 /someapi/users/123/details?name='abc'&age=20&...

Use the snippet

  let url = '/someapi/users/{id}/details';
  let urlParams = {id: 123};
  let queryParams = {name: 'abc', age: 20 };

  buildRestUrl(url, urlParams, queryParams); //someapi/users/123/details?name='abc'&age=20&...

Installation

  $ npm install nkr_urlbuilder

Usage

import { buildRestUrl } from 'nkr_urlbuilder';

let url = '/someapi/users/{id}/details';
let urlParams = {id: 123};
let queryParams = {name: 'abc', age: 20 };

const response = await fetch(buildRestUrl(url, urlParams, queryParams));

Note: First step towards opensource contribution