2.2 URL Components

URL-related functions. For more information on URL objects refer to the URL manual.

Function: restlib-url-parse URL
  • URL: string or URL object

Convenience function to return a parsed object given URL string.

If the URL is already a parsed object then it will pass through.

Function: restlib-url-filename URL
  • URL: string or URL object

Get URL filename.

Extract filename via url-filename.

Example:

(restlib-url-filename "https://heythey.com/mary?a=b&c=d%2Ce")

Result:

"/mary?a=b&c=d%2Ce"
Function: restlib-url-path URL
  • URL: string or URL object

Get URL path.

Extract only path from URL, omitting query parameters and fragment.

Example:

(restlib-url-path "https://heythey.com/mary?a=b&c=d%2Ce")

Result:

"/mary"
Function: restlib-url-query URL
  • URL: string or URL object

Get URL query.

Extract query as string from URL.

Example:

(restlib-url-query "https://heythey.com/mary?a=b&c=d%2Ce")

Result:

"a=b&c=d%2Ce"
Function: restlib-url-query-items URL
  • URL: string or URL object

Extract query items from URL.

Extract query items using url-parse-query-string.

Example:

(restlib-url-query-items "https://heythey.com/mary?a=b&c=d%2Ce")

Result:

(("c" "d,e") ("a" "b"))
Function: restlib-url-add-query-items URL ITEMS &optional OBJ-RESULT SEMICOLONS KEEP-EMPTY
  • URL: string or URL object
  • ITEMS: list of lists as specified for url-build-query-string
  • OBJ-RESULT: if non-nil then return URL object, else string
  • SEMICOLONS: if non-nil then use ‘;’ as separator
  • KEEP-EMPTY: if non-nil then render ‘key=’ instead of ‘key’

Add query ITEMS to URL.

If URL has an existing query fragment, then ITEMS will be naively appended to it, with no regard for duplicate keys.

Example:

(restlib-url-add-query-items
 "https://heythey.com/mary?a=b&c=d%2Ce"
 '(("f" "j")))

Result:

"https://heythey.com/mary?c=d,e&a=b&f=j"
Function: restlib-url-remove-query URL &optional OBJ-RESULT
  • URL: string or URL object
  • OBJ-RESULT: if non-nil then return URL object

Remove query from URL.

Example:

(restlib-url-remove-query "https://heythey.com/mary?a=b&c=d%2Ce")

Result:

"https://heythey.com/mary"