Socket
Book a DemoInstallSign in
Socket

urlfactory-js

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

urlfactory-js

This library builds the urls depending on the selected environment

1.0.6
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

UrlFactory

This library helps you handling and building the urls depending on current environment.

Installation

yarn add urlfactory-js

or

npm i urlfactory-js --save

Basic Usage

Create the UrlFactory:

const UrlFactory = require('urlfactory-js');
const urlConfig = require('../../config/urls/urls.config.json'); // path to urls config file
const urlFactory = new UrlFactory(urlConfig, 'DEV'); // 'DEV' is the name of the environment you want to use

Get the urls:

const url = urlFactory.getUrl('RETRIEVE_FAQ');

Config File Instructions

Config Example

Here you can see an example:

{
	"$schema": "https://raw.githubusercontent.com/gianlucaparadise/urlfactory-js/master/urls.schema.json",
	"hosts": {
		"DEV": {
			"default": "http://dev.example.com",
			"CMS": "https://dev.wpexample.com",
			"PROFILER": "https://dev.profiler.com"
		},
		"TEST": {
			"default": "http://test.example.com",
			"CMS": "https://test.wpexample.com",
			"PROFILER": "https://test.profiler.com"
		}
	},
	"urls": {
		"RETRIEVE_ZONES": {
			"hostKey": "CMS",
			"path": "/api/zones"
		},
		"RETRIEVE_FAQ": {
			"hostKey": "CMS",
			"path": "/api/faqs"
		},
		"RETRIEVE_USER": {
			"hostKey": "PROFILER",
			"path": "/api/user"
		},
		"CHANGE_PASSWORD": {
			"hostKey": "PROFILER",
			"path": "/api/password/change"
		},
		"CONTACT_US": {
			"hostKey": "PROFILER",
			"path": "/api/contact"
		},
		"RETRIEVE_TICKETS_MISSING_HOST": {
			"hostKey": "TICKETS",
			"path": "/api/tickets"
		},
		"RETRIEVE_USER_FORMATTED": {
			"hostKey": "CMS",
			"path": "/{0}/user/{1}"
		}
	}
}

Apply JSON Schema

You can write your configurations in a file named *.urls.json. For applying the JSON Schema validator in VS Code, add this configuration in your settings.json file:

"json.schemas": [
	{
		"fileMatch": [
			"/*.urls.json"
		],
		"url": "https://raw.githubusercontent.com/gianlucaparadise/urlfactory-js/master/urls.schema.json"
	}
]

Otherwise you can include this line on top of your config file (see Config Example)

"$schema": "https://raw.githubusercontent.com/gianlucaparadise/urlfactory-js/master/urls.schema.json"

Keywords

url

FAQs

Package last updated on 04 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.