Skip to content

Commit

Permalink
Documentation links, partial.
Browse files Browse the repository at this point in the history
Partially done update of links to API documentation.
Now referring to codox generated documentation for API.
  • Loading branch information
neotyk committed Dec 27, 2011
1 parent f7e881b commit 9e8329a
Showing 1 changed file with 47 additions and 50 deletions.
97 changes: 47 additions & 50 deletions docs.org
Expand Up @@ -10,11 +10,10 @@
#+BEGIN_SRC clojure
(defproject your-project "1.0.0-SNAPSHOT"
:description "Your project description"
:dependencies [[org.clojure/clojure "1.2.1"]
[org.clojure/clojure-contrib "1.2.0"]
[http.async.client "0.3.1"]])
:dependencies [[org.clojure/clojure "1.3.0"]
[http.async.client "0.4.0-SNAPSHOT"]])
#+END_SRC
Make sure that your project depends on at least 1.2.0 Clojure as
Make sure that your project depends on at least 1.3.0 Clojure as
*http.async.client* will not run in earlier versions.
** Require
Require it from your code:
Expand All @@ -39,18 +38,16 @@
#+BEGIN_SRC clojure
(client/GET <client> url)
#+END_SRC
Result will be a map of [[http://neotyk.github.com/http.async.client/autodoc/http.async.client-api.html#http.async.client.util/promise][*http.async.client.util/promise*]]s, and
represents response.
Do not fear, this is [[http://richhickey.github.com/clojure/clojure.core-api.html#clojure.core/promise][clojure.core/promise]] that was extended to be
able to check if it was delivered.
Result will be a map of [[http://clojuredocs.org/clojure_core/clojure.core/promise][*clojure.core/promise*]]s, and represents
response.

Following HTTP methods have been covered so far:
- [[http://neotyk.github.com/http.async.client/autodoc/http.async.client-api.html#http.async.client/GET][GET]]
- [[http://neotyk.github.com/http.async.client/autodoc/http.async.client-api.html#http.async.client/POST][POST]]
- [[http://neotyk.github.com/http.async.client/autodoc/http.async.client-api.html#http.async.client/PUT][PUT]]
- [[http://neotyk.github.com/http.async.client/autodoc/http.async.client-api.html#http.async.client/DELETE][DELETE]]
- [[http://neotyk.github.com/http.async.client/autodoc/http.async.client-api.html#http.async.client/HEAD][HEAD]]
- [[http://neotyk.github.com/http.async.client/autodoc/http.async.client-api.html#http.async.client/OPTIONS][OPTIONS]]
- [[http://neotyk.github.com/http.async.client/doc/http.async.client.html#var-GET][GET]]
- [[http://neotyk.github.com/http.async.client/doc/http.async.client.html#var-POST][POST]]
- [[http://neotyk.github.com/http.async.client/doc/http.async.client.html#var-PUT][PUT]]
- [[http://neotyk.github.com/http.async.client/doc/http.async.client.html#var-DELETE][DELETE]]
- [[http://neotyk.github.com/http.async.client/doc/http.async.client.html#var-HEAD][HEAD]]
- [[http://neotyk.github.com/http.async.client/doc/http.async.client.html#var-OPTIONS][OPTIONS]]
For detailed description see [[*HTTP%20methods][HTTP methods]].

You can submit options to HTTP methods as keyworded arguments,
Expand All @@ -61,7 +58,7 @@
Following options are supported:
- *:query* :: query parameters
- *:headers* :: custom headers to be sent out
- *:body* :: body to be sent, allowed only with [[http://neotyk.github.com/http.async.client/autodoc/http.async.client-api.html#http.async.client/PUT][PUT]]/[[http://neotyk.github.com/http.async.client/autodoc/http.async.client-api.html#http.async.client/POST][POST]]
- *:body* :: body to be sent, allowed only with [[http://neotyk.github.com/http.async.client/doc/http.async.client.html#var-PUT][PUT]]/[[http://neotyk.github.com/http.async.client/doc/http.async.client.html#var-POST][POST]]
- *:cookies* :: cookies to be sent
- *:proxy* :: proxy to be used
For detailed usage of options see [[*Request%20options][Request options]].
Expand Down Expand Up @@ -113,15 +110,15 @@
** HTTP methods
HTTP methods and convenience functions to request them.
*** GET
Most basic invocation of [[http://neotyk.github.com/http.async.client/autodoc/http.async.client-api.html#http.async.client/GET][*http.async.client/GET*]] is only with
Most basic invocation of [[http://neotyk.github.com/http.async.client/doc/http.async.client.html#var-GET][*http.async.client/GET*]] is only with
*url* you want to get.
Extended invocation includes options that can be any options
accepted by [[http://neotyk.github.com/http.async.client/autodoc/http.async.client-api.html#http.async.client.request/prepare-request][*http.async.client.request/prepare-request*]]
accepted by [[http://neotyk.github.com/http.async.client/doc/http.async.client.request.html#var-prepare-request][*http.async.client.request/prepare-request*]]
[:headers :query ..].

Simple invocation:
#+BEGIN_SRC clojure
(with-open [client (client/create-client)] ;; Create client
(with-open [client (client/create-client)] ; Create client
(let [resp (client/GET client "<your url>")
status (client/status resp)
headers (client/headers resp)]
Expand All @@ -132,7 +129,7 @@

Invocation with query parameters:
#+BEGIN_SRC clojure
(with-open [client (client/create-client)] ;; Create client
(with-open [client (client/create-client)] ; Create client
(let [resp (client/GET client "<your url>" :query {:param-name "some-value"})
status (client/status resp)
headers (client/headers resp)]
Expand All @@ -143,7 +140,7 @@

Invocation with proxy:
#+BEGIN_SRC clojure
(with-open [client (client/create-client)] ;; Create client
(with-open [client (client/create-client)] ; Create client
(let [resp (client/GET client "<your url>"
:query {:param-name "some-value"}
:proxy {:host host :port port})
Expand All @@ -155,7 +152,7 @@

Invocation with cookies:
#+BEGIN_SRC clojure
(with-open [client (client/create-client)] ;; Create client
(with-open [client (client/create-client)] ; Create client
(let [resp (client/GET client "http://localhost:8123/cookie"
;; Send cookie
:cookies #{{:domain "http://localhost:8123/"
Expand All @@ -164,15 +161,15 @@
:path "/cookie"
:max-age 10
:secure false}})]
(doseq [cookie (client/cookies resp)] ;; Read cookies from server response
(doseq [cookie (client/cookies resp)] ; Read cookies from server response
(println "name:" (:name cookie) ", value:" (:value cookie)))))
#+END_SRC
Notice [[http://neotyk.github.com/http.async.client/autodoc/http.async.client-api.html#http.async.client/cookies][*http.async.client/cookies*]] function extracts cookies from
Notice [[http://neotyk.github.com/http.async.client/doc/http.async.client.html#var-cookies][*http.async.client/cookies*]] function extracts cookies from
response headers, so to start processing it you don't need to wait
for whole response to arrive.
*** PUT/POST
[[http://neotyk.github.com/http.async.client/autodoc/http.async.client-api.html#http.async.client/PUT][*http.async.client/PUT*]]/[[http://neotyk.github.com/http.async.client/autodoc/http.async.client-api.html#http.async.client/POST][*http.async.client/POST*]] work the same
way as [[*%20http%20neotyk%20github%20com%20http%20async%20client%20autodoc%20http%20async%20client%20api%20html%20http%20async%20client%20GET%20GET][*GET*]] but they also accept *:body* argument.
[[http://neotyk.github.com/http.async.client/doc/http.async.client.html#var-PUT][*http.async.client/PUT*]]/[[http://neotyk.github.com/http.async.client/doc/http.async.client.html#var-POST][*http.async.client/POST*]] work the same
way as [[*GET][*GET*]] but they also accept *:body* argument.

*:body* can be:
- String
Expand All @@ -182,15 +179,15 @@
**** Submitting body as String
You can send String as body with PUT/POST:
#+BEGIN_SRC clojure
(with-open [client (client/create-client)] ;; Create client
(with-open [client (client/create-client)] ; Create client
(let [resp (client/POST client "<your url>" :body "SampleBody")]
; do something with resp
))
#+END_SRC
**** Submitting form parameters
Submitting parameters via body map:
#+BEGIN_SRC clojure
(with-open [client (client/create-client)] ;; Create client
(with-open [client (client/create-client)] ; Create client
(let [resp (client/POST client "<your url>" :body {:u "user" :p "s3cr3t"})]
; do something with resp
))
Expand All @@ -199,7 +196,7 @@
Another method to provide body is via InputStream:
#+BEGIN_SRC clojure
(use '[clojure.java.io :only [input-stream]])
(with-open [client (client/create-client)] ;; Create client
(with-open [client (client/create-client)] ; Create client
(let [resp (client/PUT client "<your url>" :body (input-stream (.getBytes "SampleContent" "UTF-8")))]
; do something with resp
))
Expand All @@ -208,29 +205,29 @@
To use zero byte copy future, provide a File as :body
#+begin_src clojure
(import '(java.io File))
(with-open [client (client/create-client)] ;; Create client
(with-open [client (client/create-client)] ; Create client
(let [resp (client/PUT "<your url>" :body (File. "<path to file>"))]
;; do something with resp
; do something with resp
))
#+end_src
*** DELETE
To call [[http://neotyk.github.com/http.async.client/autodoc/http.async.client-api.html#http.async.client/DELETE][*http.async.client/DELETE*]] on a resource:
To call [[http://neotyk.github.com/http.async.client/doc/http.async.client.html#var-DELETE][*http.async.client/DELETE*]] on a resource:
#+BEGIN_SRC clojure
(with-open [client (client/create-client)] ;; Create client
(with-open [client (client/create-client)] ; Create client
(let [resp (client/DELETE "<your url>")]
; do something with resp
))
#+END_SRC
*** HEAD
To call [[http://neotyk.github.com/http.async.client/autodoc/http.async.client-api.html#http.async.client/HEAD][*http.async.client/HEAD*]] on a resource:
To call [[http://neotyk.github.com/http.async.client/doc/http.async.client.html#var-HEAD][*http.async.client/HEAD*]] on a resource:
#+BEGIN_SRC clojure
(with-open [client (client/create-client)] ;; Create client
(let [resp (client/HEAD "<your url>")]
; do something with resp
))
#+END_SRC
*** OPTIONS
To call [[http://neotyk.github.com/http.async.client/autodoc/http.async.client-api.html#http.async.client/OPTIONS][*http.async.client/OPTIONS*]] on a resource:
To call [[http://neotyk.github.com/http.async.client/doc/http.async.client.html#var-OPTIONS][*http.async.client/OPTIONS*]] on a resource:
#+BEGIN_SRC clojure
(with-open [client (client/create-client)] ;; Create client
(let [resp (client/OPTIONS "<your url>")]
Expand Down Expand Up @@ -465,7 +462,7 @@
you actually asynchronously execute HTTP request.
Some times you might need to wait for response processing to be
done before proceeding, in order to do so you call
[[http://neotyk.github.com/http.async.client/autodoc/http.async.client-api.html#http.async.client/await][*http.async.client/await*]].
[[http://neotyk.github.com/http.async.client/doc/http.async.client.html#var-await][*http.async.client/await*]].
It takes only one argument, that is response and returns once
receiving has finished.
#+BEGIN_SRC clojure
Expand All @@ -482,7 +479,7 @@
(client/string (client/await resp))))
#+END_SRC
*** Reading status line
[[http://neotyk.github.com/http.async.client/autodoc/http.async.client-api.html#http.async.client/status][*http.async.client/status*]] returns status lazy map of response.
[[http://neotyk.github.com/http.async.client/doc/http.async.client.html#var-status][*http.async.client/status*]] returns status lazy map of response.
It will wait until HTTP Status has been received.
#+BEGIN_SRC clojure
(with-open [client (client/create-client)] ;; Create client
Expand All @@ -494,7 +491,7 @@
after this returns headers and body, might not been delivered
yet.
*** Reading headers
[[http://neotyk.github.com/http.async.client/autodoc/http.async.client-api.html#http.async.client/headers][*http.async.client/headers*]] returns headers lazy map of response.
[[http://neotyk.github.com/http.async.client/doc/http.async.client.html#var-headers][*http.async.client/headers*]] returns headers lazy map of response.
It will wait until HTTP Headers are received.
#+BEGIN_SRC clojure
(with-open [client (client/create-client)] ;; Create client
Expand All @@ -505,7 +502,7 @@
Again, like in case of status, body might not have been delivered
yet after this returns.
*** Reading cookies
[[http://neotyk.github.com/http.async.client/autodoc/http.async.client-api.html#http.async.client/cookies][*http.async.client/cookies*]] returns seq of maps representing
[[http://neotyk.github.com/http.async.client/doc/http.async.client.html#var-cookies][*http.async.client/cookies*]] returns seq of maps representing
cookies.
It will wait until HTTP Headers are received.
#+BEGIN_SRC clojure
Expand All @@ -517,13 +514,13 @@
Sample above will return sequence of cookie names that server has
set.
*** Reading body
[[http://neotyk.github.com/http.async.client/autodoc/http.async.client-api.html#http.async.client/body][*http.async.client/body*]] returns either ByteArrayOutputStream or
[[http://neotyk.github.com/http.async.client/doc/http.async.client.html#var-body][*http.async.client/body*]] returns either ByteArrayOutputStream or
seq of it, depending if you used [[*Asynchronous%20operations][Asynchronous operations]] or
[[*Streaming][Streaming]] respectively.
It will *not* wait for response to be finished, it will return as
soon as first chunk of HTTP response body is received.
*** Reading body as string
[[http://neotyk.github.com/http.async.client/autodoc/http.async.client-api.html#http.async.client/string][*http.async.client/string*]] returns either string or seq of
[[http://neotyk.github.com/http.async.client/doc/http.async.client.html#var-string][*http.async.client/string*]] returns either string or seq of
strings, again depending if you used [[*Asynchronous%20operations][Asynchronous operations]] or
[[*Streaming][Streaming]] respectively.
It will *not* wait for response to be finished, it will return as
Expand All @@ -534,7 +531,7 @@
(client/string (client/await resp))))
#+END_SRC
Sample above will return string of response body.
[[http://neotyk.github.com/http.async.client/autodoc/http.async.client-api.html#http.async.client/string][*http.async.client/string*]] is lazy so you can use it in case of
[[http://neotyk.github.com/http.async.client/doc/http.async.client.html#var-string][*http.async.client/string*]] is lazy so you can use it in case of
streams as well.
#+BEGIN_SRC clojure
(with-open [client (client/create-client)] ;; Create client
Expand All @@ -546,7 +543,7 @@
Sample above will print parts as they are received, and will
return once response receiving is finished.
*** Reading error
[[http://neotyk.github.com/http.async.client/autodoc/http.async.client-api.html#http.async.client/error][*http.async.client/error*]] will return Throwable that was cause of
[[http://neotyk.github.com/http.async.client/doc/http.async.client.html#var-error][*http.async.client/error*]] will return Throwable that was cause of
request failure iff request failed, else *nil*.
#+BEGIN_SRC clojure
(with-open [client (client/create-client)] ;; Create client
Expand All @@ -557,7 +554,7 @@
#+END_SRC
*** Canceling request
At any given time of processing HTTP Response you can *cancel* it
by calling [[http://neotyk.github.com/http.async.client/autodoc/http.async.client-api.html#http.async.client/cancel][*http.async.client/cancel*]].
by calling [[http://neotyk.github.com/http.async.client/doc/http.async.client.html#var-cancel][*http.async.client/cancel*]].
#+BEGIN_SRC clojure
(with-open [client (client/create-client)] ;; Create client
(let [resp (client/GET client url)]
Expand All @@ -567,7 +564,7 @@
*** Response predicates
You can also check status of request.
**** done?
[[http://neotyk.github.com/http.async.client/autodoc/http.async.client-api.html#http.async.client/done?][*http.async.client/done?*]] will tell you if response processing
[[http://neotyk.github.com/http.async.client/doc/http.async.client.html#var-done?][*http.async.client/done?*]] will tell you if response processing
has finished:
#+BEGIN_SRC clojure
(with-open [client (client/create-client)] ;; Create client
Expand All @@ -579,15 +576,15 @@
Sample above will check if response was finished, if not - will
wait for it and return true as a result of call to done?.
**** failed?
[[http://neotyk.github.com/http.async.client/autodoc/http.async.client-api.html#http.async.client/failed?][*http.async.client/failed?*]] will return true iff request has
[[http://neotyk.github.com/http.async.client/doc/http.async.client.html#var-failed?][*http.async.client/failed?*]] will return true iff request has
failed. If this return true you can [[*Reading%20error][read error]].
**** canceled?
[[http://neotyk.github.com/http.async.client/autodoc/http.async.client-api.html#http.async.client/canceled?][*http.async.client/canceled?*]] will return true iff request has
[[http://neotyk.github.com/http.async.client/doc/http.async.client.html#var-canceled?][*http.async.client/canceled?*]] will return true iff request has
been [[*Canceling%20request][canceled]], else false is return.
** Managing client
*** Branding
*http.async.client* can be configured with User-Agent. To do so
you can use [[http://neotyk.github.com/http.async.client/autodoc/http.async.client-api.html#http.async.client/create-client][*http.async.client/create-client*]] and remember to
you can use [[http://neotyk.github.com/http.async.client/doc/http.async.client.html#var-create-client][*http.async.client/create-client*]] and remember to
close created client yourself, best is to use it within macro
like with-open, though make sure that body of it will wait for
whore response to finish.
Expand Down Expand Up @@ -723,8 +720,8 @@
#+END_SRC
*** Closing *http.async.client*
Whenever you've created *http.async.client* via
[[http://neotyk.github.com/http.async.client/autodoc/http.async.client-api.html#http.async.client/create-client][*http.async.client/create-client*]] you will need to close it.
To do so you call [[http://neotyk.github.com/http.async.client/autodoc/http.async.client-api.html#http.async.client/close][*http.async.client/close*]], *http.async.client*
[[http://neotyk.github.com/http.async.client/doc/http.async.client.html#var-create-client][*http.async.client/create-client*]] you will need to close it.
To do so you call [[http://neotyk.github.com/http.async.client/doc/http.async.client.html#var-close][*http.async.client/close*]], *http.async.client*
relies on client been bound to **client**.
#+BEGIN_SRC clojure
(let [client (client/create-client)]
Expand Down Expand Up @@ -810,5 +807,5 @@
default callbacks. This fill allow you to easy change only few
callbacks and reuse default for the rest.

Please look at source of [[http://neotyk.github.com/http.async.client/autodoc/http.async.client-api.html#http.async.client/stream-seq][*http.async.client/stream-seq*]] to see
Please look at source of [[http://neotyk.github.com/http.async.client/doc/http.async.client.html#var-stream-seq][*http.async.client/stream-seq*]] to see
how to do it.

0 comments on commit 9e8329a

Please sign in to comment.