File: walkthrough.clj

package info (click to toggle)
lambdaisland-uri-clojure 1.13.95-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 240 kB
  • sloc: xml: 88; sh: 28; makefile: 12
file content (50 lines) | stat: -rw-r--r-- 1,175 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
(ns repl-sessions.walkthrough
  (:require [lambdaisland.uri :as uri]
            [lambdaisland.uri.normalize :as normalize]))

(def u (uri/uri "https://lambdaisland.com/episodes/all"))

(type u)
(record? u)

(str u)

(into {} (uri/uri "https://lambdaisland.com/episodes/all"))
;; => {:scheme "https",
;;     :user nil,
;;     :password nil,
;;     :host "lambdaisland.com",
;;     :port nil,
;;     :path "/episodes/all",
;;     :query nil,
;;     :fragment nil}

(:host u)
(:path u)
(assoc u :fragment "hello")
(assoc u :path "")

(str u)

(uri/uri u)
(uri/uri (java.net.URI. "http://example.com"))

(def base "http://example.com/api/v1/")

(uri/join base "hello/world")
(uri/join base "/hello/world")
(uri/join base "./hello/../../world")

(uri/query-map "http://example.com/?foo=bar&hello=world")

(-> "http://example.com/?foo=bar&hello=world"
    (uri/assoc-query :foo 123))

(-> "http://example.com/?foo=bar&hello=world"
    (uri/assoc-query :foo [123 456]))

(-> "http://example.com/?foo=bar&hello=world"
    (uri/assoc-query :foo "foo bar"))

(normalize/normalize (uri/uri "http://example.com/🙈🙉"))
(normalize/normalize (uri/uri "http://example.com/%61%62%63"))