Blame


1 1d126b15 2021-10-13 op # Gemini library for clojure
2 1d126b15 2021-10-13 op
3 1d126b15 2021-10-13 op `gemini.core` is a clojure library to make Gemini requests.
4 1d126b15 2021-10-13 op
5 1d126b15 2021-10-13 op
6 1d126b15 2021-10-13 op ## Usage
7 1d126b15 2021-10-13 op
8 1d126b15 2021-10-13 op ```clojure
9 1d126b15 2021-10-13 op user=> (require '[gemini.core :as gemini])
10 1d126b15 2021-10-13 op ```
11 1d126b15 2021-10-13 op
12 1d126b15 2021-10-13 op #### fetch
13 1d126b15 2021-10-13 op
14 1d126b15 2021-10-13 op `fetch` makes a Gemini request and returns a map with `:request`,
15 1d126b15 2021-10-13 op `:meta`, `:code` and `:body` as keys, or `:error` if an error occur.
16 1d126b15 2021-10-13 op
17 1d126b15 2021-10-13 op The request needs to be closed afterwards using `close`, or calling
18 1d126b15 2021-10-13 op the `.close` method on the `:request` object.
19 1d126b15 2021-10-13 op
20 1d126b15 2021-10-13 op ```clojure
21 1d126b15 2021-10-13 op user=> (gemini/fetch "gemini://gemini.circumlunar.space/")
22 1d126b15 2021-10-13 op {:request
23 1d126b15 2021-10-13 op #object[com.omarpolo.gemini.Request 0x3b270767 "com.omarpolo.gemini.Request@3b270767"],
24 1d126b15 2021-10-13 op :meta "gemini://gemini.circumlunar.space/",
25 1d126b15 2021-10-13 op :code 31,
26 1d126b15 2021-10-13 op :body
27 1d126b15 2021-10-13 op #object[java.io.BufferedReader 0x49358b66 "java.io.BufferedReader@49358b66"]}
28 1d126b15 2021-10-13 op ```
29 1d126b15 2021-10-13 op
30 1d126b15 2021-10-13 op #### body-as-string!
31 1d126b15 2021-10-13 op
32 1d126b15 2021-10-13 op Read all the response into a string and returns it. It also closes
33 1d126b15 2021-10-13 op the request automatically.
34 1d126b15 2021-10-13 op
35 1d126b15 2021-10-13 op ```clojure
36 1d126b15 2021-10-13 op user=> (-> (gemini/fetch "gemini://gemini.circumlunar.space/")
37 1d126b15 2021-10-13 op gemini/body-as-string!)
38 1d126b15 2021-10-13 op "# Project Gemini\n\n## Overview\n\nGemini is a new internet protocol which..."
39 1d126b15 2021-10-13 op ```
40 1d126b15 2021-10-13 op
41 1d126b15 2021-10-13 op #### close
42 1d126b15 2021-10-13 op
43 1d126b15 2021-10-13 op Closes a request.
44 1d126b15 2021-10-13 op
45 1d126b15 2021-10-13 op #### with-request
46 1d126b15 2021-10-13 op
47 1d126b15 2021-10-13 op Like `with-open`, but specifically for the requests:
48 1d126b15 2021-10-13 op
49 1d126b15 2021-10-13 op ```clojure
50 1d126b15 2021-10-13 op user=> (with-request [req (fetch "gemini://gemini.circumlunar.space/")]
51 1d126b15 2021-10-13 op ,,,)
52 1d126b15 2021-10-13 op ```