Skip to main content

Web API - URL API

Web API'S - URL API


What is URL?


A Uniform Resource Locator (URL) is a reference to a web resource that specifies its location on a computer network and a mechanism for retrieving it.
Examples of URL.
https://www.example.com/page1.html
http://www.example.com/en/us/doc
https://example.com/empolyee/1
https://example.com/employee?sort=A&search=muru
Syntax

URI = scheme:[//authority]path[?query][#fragment]

authority = [userinfo@]host[:port]

options Description
scheme The first part of the URL is the scheme, which indicates the protocol that the browser must use to request the resouce.
path /path/to/myfile.html is the path to the resource on the Web server.
query ?key1=value1&key2=value2 are extra parameters provided to the Web server. Those parameters are a list of key/value pairs separated with the & symbol.
fragment #fragment is an anchor to another part of the resource itself
URL javascript usage
Example 1
let addr = new URL("https://example.com:80/path/to/page?search=DATA");
console.log(addr.protocol); // https:
console.log(addr.host); // example.com:80
console.log(addr.hostname); // example.com
console.log(addr.port); // 80
console.log(addr.pathname); // /path/to/page
console.log(addr.searchParams.get("search")); // DATA
view raw url-api-1.js hosted with ❤ by GitHub
Example 2
let addr = new URL("https://murugan:password@example.com:80/path/to/page?search=DATA");
console.log(addr.username); //murugan
console.log(addr.password); // password
console.log(addr.protocol); // https:
console.log(addr.host); // example.com:80
console.log(addr.hostname); // example.com
console.log(addr.port); // 80
console.log(addr.pathname); // /path/to/page
console.log(addr.searchParams.get("search")); // DATA
view raw url-api-2.js hosted with ❤ by GitHub
Console

Comments

Popular posts from this blog

Hide/Show Password using Eye icon in angular

Let's create simple LoadBalancer Server - Node JS

JVM Languages