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 |
Example 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Comments
Post a Comment