on aa7a67f help sign in
elk/libraries/Http.elm
42 lines 1.4 kB history raw
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.
5module Http where
7import Native.Http (send)
9-- The datatype for responses. Success contains only the returned message.
10-- Failures contain both an error code and an error message.
11data Response a = Success a | Waiting | Failure Int String
13type Request a = {
14 verb : String,
15 url : String,
16 body : a,
17 headers : [(String,String)]
18 }
20-- Create a customized request. Arguments are request type (get, post, put,
21-- delete, etc.), target url, data, and a list of additional headers.
22request : String -> String -> String -> [(String,String)] -> Request String
23request = Request
25-- Create a GET request to the given url.
26get : String -> Request String
27get url = Request "GET" url "" []
29-- Create a POST request to the given url, carrying the given data.
30post : String -> String -> Request String
31post url body = Request "POST" url body []
34-- Performs an HTTP request with the given requests. Produces a signal
35-- that carries the responses.
36send : Signal (Request a) -> Signal (Response String)
38-- Performs an HTTP GET request with the given urls. Produces a signal
39-- that carries the responses.
40sendGet : Signal String -> Signal (Response String)
41sendGet reqs = send (lift get reqs)