@@ -1,6 +1,14 @@
1−-- A library for asynchronous HTTP requests (AJAX). See the
2−-- [WebSocket](http://elm-lang.org/docs/WebSocket.elm) library if
3−-- you have very strict latency requirements.
1+{-| A library for asynchronous HTTP requests (AJAX). See the
2+[WebSocket](http://elm-lang.org/docs/WebSocket.elm) library if
3+you have very strict latency requirements.
4+
5+# Types
6+@docs Request, Response
7+
8+# Making requests
9+@docs request, get, post, send, sendGet
10+
11+-}
412
513module Http where
614
@@ -8,8 +16,9 @@ import open Basics
816import open Signal
917import Native.Http
1018
11−-- The datatype for responses. Success contains only the returned message.
12−-- Failures contain both an error code and an error message.
19+{-| The datatype for responses. Success contains only the returned message.
20+Failures contain both an error code and an error message.
21+-}
1322data Response a = Success a | Waiting | Failure Int String
1423
1524type Request a = {
@@ -19,27 +28,28 @@ type Request a = {
1928 headers : [(String,String)]
2029 }
2130
22−-- Create a customized request. Arguments are request type (get, post, put,
23−-- delete, etc.), target url, data, and a list of additional headers.
31+{-| Create a customized request. Arguments are request type (get, post, put,
32+delete, etc.), target url, data, and a list of additional headers.
33+-}
2434request : String -> String -> String -> [(String,String)] -> Request String
2535request = Request
2636
27−-- Create a GET request to the given url.
37+{-| Create a GET request to the given url. -}
2838get : String -> Request String
2939get url = Request "GET" url "" []
3040
31−-- Create a POST request to the given url, carrying the given data.
41+{-| Create a POST request to the given url, carrying the given data. -}
3242post : String -> String -> Request String
3343post url body = Request "POST" url body []
3444
35−
36−-- Performs an HTTP request with the given requests. Produces a signal
37−-- that carries the responses.
45+{-| Performs an HTTP request with the given requests. Produces a signal
46+that carries the responses.
47+-}
3848send : Signal (Request a) -> Signal (Response String)
3949send = Native.Http.send
4050
41−-- Performs an HTTP GET request with the given urls. Produces a signal
42−-- that carries the responses.
51+{-| Performs an HTTP GET request with the given urls. Produces a signal
52+that carries the responses.
53+-}
4354sendGet : Signal String -> Signal (Response String)
4455sendGet reqs = send (lift get reqs)
45−