diff --git a/README.md b/README.md
index 60f3037..911f4a9 100644
--- a/README.md
+++ b/README.md
@@ -3,6 +3,14 @@
A minimal request library for and in zepto.
Requires at least version 0.9.2.
+Documentation can be generated with `zeps`.
+
+## Installation
+
+```
+zeps install hellerve/request
+```
+
## Usage
This library exposes a few endpoints for simple
diff --git a/module.zp b/module.zp
index 78dd4ce..5c97a1d 100644
--- a/module.zp
+++ b/module.zp
@@ -1,12 +1,12 @@
-#{:name "request"
- :version "1.0.0"
- :license "GPLv2"
+#{:name "request"
+ :version "1.0.1"
+ :license "GPLv2"
:tests []
:type :library
- :author #{:name "Veit Heller"
- :email "veit@veitheller.de"
+ :author #{:name "Veit Heller"
+ :email "veit@veitheller.de"
:github "@hellerve"}
- :location #{:github "hellerve/request"
+ :location #{:github "hellerve/request"
:zpr "request"}
:zepto #{:version :any
:ez #f
diff --git a/request.zp b/request.zp
index e576653..a0ffe65 100644
--- a/request.zp
+++ b/request.zp
@@ -15,12 +15,30 @@
(FOLLOW-REDIRECTS #f)
(set-buffer-size (lambda (nsize)
+ "sets the buffer size of the socket buffer.
+
+ params:
+ - nsize: an integer denoting the size
+ complexity: O(1)
+ returns: the new value"
(set! BSIZE nsize)))
(set-default-headers (lambda (headers)
+ "sets the default headers (normally only the user agent is set).
+
+ params:
+ - headers: a hashmap mapping header names to values
+ complexity: O(1)
+ returns: the new value"
(set! DFLT-HEADERS headers)))
(set-follow-redirects (lambda (flag)
+ "sets the flag whether the library should follow redirects.
+
+ params:
+ - flag: the boolean
+ complexity: O(1)
+ returns: the new value"
(set! FOLLOW-REDIRECTS flag)))
(end-request (lambda (res sock)
@@ -79,6 +97,15 @@
size)))))))
(request (lambda (scheme path opts)
+ "performs a request to path (scheme is a string denoting the method).
+ Options are given as the optional argument opts.
+
+ params:
+ - path: the resource to access
+ - scheme: the method type (e.g. \"PUT\" or \"DELETE\")
+ - opts: the options (accepted keys are :headers and :body)
+ complexity: O(1) (heavily dependent on the network and request/response)
+ returns: a hashmap with the keys :headers, :body, :status, and :request"
(let* ((path (if (string:starts-with path "http://") (substring path 7 (length path)) path))
(path (if (string:starts-with path "https://") (substring path 8 (length path)) path))
(split (string:split path #\/))
@@ -119,16 +146,56 @@
(loop (net:recv sock (min BSIZE (- len cur))) (++ bytes recvd) ncur len)))))))))
(head (lambda (path . opts)
+ "performs a HEAD request to path. Options are given as the optional argument
+ opts.
+
+ params:
+ - path: the resource to access
+ - opts: the options (accepted keys are :headers and :body)
+ complexity: O(1) (heavily dependent on the network and request/response)
+ returns: a hashmap with the keys :headers, :body, :status, and :request"
(request "HEAD" path (get-from opts 0 #{}))))
(get (lambda (path . opts)
+ "performs a GET request to path. Options are given as the optional argument
+ opts.
+
+ params:
+ - path: the resource to access
+ - opts: the options (accepted keys are :headers and :body)
+ complexity: O(1) (heavily dependent on the network and request/response)
+ returns: a hashmap with the keys :headers, :body, :status, and :request"
(request "GET" path (get-from opts 0 #{}))))
(post (lambda (path . opts)
+ "performs a POST request to path. Options are given as the optional argument
+ opts.
+
+ params:
+ - path: the resource to access
+ - opts: the options (accepted keys are :headers and :body)
+ complexity: O(1) (heavily dependent on the network and request/response)
+ returns: a hashmap with the keys :headers, :body, :status, and :request"
(request "POST" path (get-from opts 0 #{}))))
(put (lambda (path . opts)
+ "performs a PUT request to path. Options are given as the optional argument
+ opts.
+
+ params:
+ - path: the resource to access
+ - opts: the options (accepted keys are :headers and :body)
+ complexity: O(1) (heavily dependent on the network and request/response)
+ returns: a hashmap with the keys :headers, :body, :status, and :request"
(request "PUT" path (get-from opts 0 #{}))))
(delete (lambda (path . opts)
+ "performs a DELETE request to path. Options are given as the optional argument
+ opts.
+
+ params:
+ - path: the resource to access
+ - opts: the options (accepted keys are :headers and :body)
+ complexity: O(1) (heavily dependent on the network and request/response)
+ returns: a hashmap with the keys :headers, :body, :status, and :request"
(request "DELETE" path (get-from opts 0 #{})))))