on master help sign in
Convert Http docs
9a0ff87Justin Leitgeb
libraries/Http.elm+25−15
@@ -1,6 +1,14 @@
1−-- A library for asynchronous HTTP requests (AJAX). See the
1+{-| A library for asynchronous HTTP requests (AJAX). See the
2−-- [WebSocket](http://elm-lang.org/docs/WebSocket.elm) library if
2+[WebSocket](http://elm-lang.org/docs/WebSocket.elm) library if
3−-- you have very strict latency requirements.
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+-}
4
12
5module Http where
13module Http where
6
14
@@ -8,8 +16,9 @@ import open Basics
8import open Signal
16import open Signal
9import Native.Http
17import Native.Http
10
18
11−-- The datatype for responses. Success contains only the returned message.
19+{-| The datatype for responses. Success contains only the returned message.
12−-- Failures contain both an error code and an error message.
20+Failures contain both an error code and an error message.
21+-}
13data Response a = Success a | Waiting | Failure Int String
22data Response a = Success a | Waiting | Failure Int String
14
23
15type Request a = {
24type Request a = {
@@ -19,27 +28,28 @@ type Request a = {
19 headers : [(String,String)]
28 headers : [(String,String)]
20 }
29 }
21
30
22−-- Create a customized request. Arguments are request type (get, post, put,
31+{-| Create a customized request. Arguments are request type (get, post, put,
23−-- delete, etc.), target url, data, and a list of additional headers.
32+delete, etc.), target url, data, and a list of additional headers.
33+-}
24request : String -> String -> String -> [(String,String)] -> Request String
34request : String -> String -> String -> [(String,String)] -> Request String
25request = Request
35request = Request
26
36
27−-- Create a GET request to the given url.
37+{-| Create a GET request to the given url. -}
28get : String -> Request String
38get : String -> Request String
29get url = Request "GET" url "" []
39get url = Request "GET" url "" []
30
40
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. -}
32post : String -> String -> Request String
42post : String -> String -> Request String
33post url body = Request "POST" url body []
43post url body = Request "POST" url body []
34
44
35−
36−-- Performs an HTTP request with the given requests. Produces a signal
45+{-| Performs an HTTP request with the given requests. Produces a signal
37−-- that carries the responses.
46+that carries the responses.
47+-}
38send : Signal (Request a) -> Signal (Response String)
48send : Signal (Request a) -> Signal (Response String)
39send = Native.Http.send
49send = Native.Http.send
40
50
41−-- Performs an HTTP GET request with the given urls. Produces a signal
51+{-| Performs an HTTP GET request with the given urls. Produces a signal
42−-- that carries the responses.
52+that carries the responses.
53+-}
43sendGet : Signal String -> Signal (Response String)
54sendGet : Signal String -> Signal (Response String)
44sendGet reqs = send (lift get reqs)
55sendGet reqs = send (lift get reqs)
45−