Resource for fetching data through http with very basic functionalities.

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
(ns foo.baz
  (:api dunaj)
  (:require [dunaj.resource :refer [status]]
            [dunaj.concurrent.thread :refer [sleep]]))

(with-io-scope
  (let [r (http "http://httpbin.org/post")
        c (acquire! (assoc r :request-method :post))
        fc (format c utf-8)]
    (println! "config" (config c))
    (println! "sent" (write! fc "key1=val1&key2=val2&key1=val3"))
    (println! "response" (str (read! fc)))
    (println! "status" @(status c))
    (sleep 100)))
;; config {:uri #uri "http://httpbin.org/post" :proxy nil :secure? false :allow-ui? nil :timeout nil :use-caches? nil :follow? nil :request-properties nil :request-method :post :chunked-streaming nil :hostname-verifier nil :ssl-context nil :batch-size nil}
;; sent 29
;; response {
;;   "args": {},
;;   "data": "",
;;   "files": {},
;;   "form": {
;;     "key1": [
;;       "val1",
;;       "val3"
;;     ],
;;     "key2": "val2"
;;   },
;;   "headers": {
;;     "Accept": "text/html, image/gif, image/jpeg, *"; q=.2, */*; q=.2",
;;     Connect-Time": "2",
;;     "Connection": "close",
;;     "Content-Length": "29",
;;     "Content-Type": "application/x-www-form-urlencoded",
;;     "Host": "httpbin.org",
;;     "Total-Route-Time": "0",
;;     "User-Agent": "Java/1.8.0_25",
;;     "Via": "1.1 vegur",
;;     "X-Request-Id": "c550e93d-a79d-47c2-aab9-d0f9c22c663d"
;;   },
;;   "json": null,
;;   "url": "http://httpbin.org/post"
;; }
;; status {:proxy? false :response-message OK :response-code 200 :request-method POST :headers {Content-Type application/json Via 1.1 vegur Date Wed, 03 Dec 2014 12:29:47 GMT Content-Length 627 Connection keep-alive Access-Control-Allow-Credentials true Access-Control-Allow-Origin * Server gunicorn/18.0 nil HTTP/1.1 200 OK}}
;;=> nil

http

Available since version 1.0 (view source)

Usage:
  • (http uri & {:as opts})

Type signature:
  • ((U nil String+ Uri) ⨯ Any) → (I IImmutableReadable IAcquirableFactory)

Returns HTTP resource factory with given uri and opts set. Note that URI scheme has precedence over any other protocol settings set in the factory.

See also: https, http-factory

http-factory

Available since version 1.0 (view source)

not referred automatically

VAR of type HttpResourceFactory

Http(s) resource factory. Current options are:

  • :uri - resource uri

  • :proxy - nil, host proxy instance or map with :type, :address and :port, where :type is one of :direct, :http or :socks.

  • :secure? - nil or true if https is requested

  • :allow-ui? - nil or boolean. Can request input from user?

  • :timeout - nil or integer or IDuration. Connection timeout.

  • :use-caches? - nil or boolean. Use resource cache?

  • :follow? - nil or boolean. Follow redirects?

  • :request-properties - nil or map with request properties.

  • :request-method - nil or request method (e.g. 'GET')

  • :chunked-streaming - nil or boolean. Host specific

  • :hostname-verifier - nil or host specific hostname verifier

  • :ssl-context - nil or host specific SSL context

  • :batch-size - batch size, low level

See also: http, https

https

Available since version 1.0 (view source)

Usage:
  • (https uri & {:as opts})

Type signature:
  • ((U nil String+ Uri) ⨯ Any) → (I IImmutableReadable IAcquirableFactory)

Returns HTTPS resource factory with given uri and opts set. Note that URI scheme has precedence over any other protocol related settings set in the factory.

See also: http, http-factory