nkr_urlbuilder
v1.0.9
Published
URL generator for REST APIs on the front-end
Downloads
12
Readme
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));