Parses URIs and URLs
The following are two example URLs and their component parts:
https://admin:hunter1@example.com:8042/over/there?name=ferret#nose \_/ \___/ \_____/ \_________/ \__/\_________/ \_________/ \__/ | | | | | | | | scheme username password hostname port path[s] query fragment
Types
QueryParams = distinct seq[(string, string)]
- Source Edit
Url = ref object scheme*, username*, password*: string hostname*, port*, fragment*: string paths*: seq[string] query*: QueryParams
- Source Edit
Procs
proc `$`(query: QueryParams): string {....raises: [], tags: [].}
- Source Edit
proc `$`(url: Url): string {....raises: [], tags: [].}
- Turns Url into a string. Preserves query string param ordering. Source Edit
proc `[]=`(query: var QueryParams; key, value: string) {....raises: [], tags: [].}
- Sets the value for the key in url.query. If the key is present, this appends a new key-value pair to the end. Source Edit
proc `[]`(query: QueryParams; key: string): string {....raises: [], tags: [].}
- Get a key out of url.query. Returns an empty string if key is not present. Use a for loop to get multiple keys. Source Edit
proc add(query: var QueryParams; params: QueryParams) {....raises: [], tags: [].}
- Source Edit
proc contains(query: QueryParams; key: string): bool {....raises: [], tags: [].}
- Returns true if key is in the url.query. "name" in url.query or "name" notin url.query Source Edit
proc decodeQueryComponent(s: string): string {....raises: [ValueError], tags: [].}
- Takes a string and decodes it from the x-www-form-urlencoded format. Source Edit
proc decodeURIComponent(s: string): string {....raises: [ValueError], tags: [].}
- Encodes the string the same as decodeURIComponent does in the browser. Source Edit
proc decodeUrlComponent(s: string): string {....raises: [ValueError], tags: [].}
- Encodes the string the same as decodeURIComponent does in the browser. Source Edit
proc encodeQueryComponent(s: string): string {....raises: [], tags: [].}
- Similar to encodeURIComponent, however query parameter spaces should be +, not %20 like encodeURIComponent would encode them. The encoded string is in the x-www-form-urlencoded format. Source Edit
proc encodeURIComponent(s: string): string {....raises: [], tags: [].}
- Encodes the string the same as encodeURIComponent does in the browser. Source Edit
proc encodeUrlComponent(s: string): string {....raises: [], tags: [].}
- Encodes the string the same as encodeURIComponent does in the browser. Source Edit
proc host(url: Url): string {....raises: [], tags: [].}
- Returns the hostname and port part of the URL as a string. Example: "example.com:8042" Source Edit
proc parseSearch(search: string): QueryParams {....raises: [ValueError], tags: [].}
- Parses the search part into strings pairs "name=&age&legs=4" -> @[("name", ""), ("age", ""), ("legs", "4")] Source Edit
proc parseUrl(s: string): Url {....raises: [ValueError], tags: [].}
- Parses a URL or a URL into the Url object. Source Edit
Converters
converter toBase(params: QueryParams): seq[(string, string)] {....raises: [], tags: [].}
- Source Edit
converter toBase(params: var QueryParams): var seq[(string, string)] {. ...raises: [], tags: [].}
- Source Edit