on 54ffaab help sign in
elk/core/HTTP.elm
41 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
7-- The datatype for responses. Success contains only the returned message.
8-- Failures contain both an error code and an error message.
9data Response a = Success a | Waiting | Failure Int String
11type Request a = {
12 verb : String,
13 url : String,
14 body : a,
15 headers : [(String,String)]
18-- Create a customized request. Arguments are request type (get, post, put,
19-- delete, etc.), target url, data, and a list of additional headers.
20request : String -> String -> String -> [(String,String)] -> Request String
21request = Request
23-- Create a GET request to the given url.
24get : String -> Request String
25get url = Request "GET" url "" []
27-- Create a POST request to the given url, carrying the given data.
28post : String -> String -> Request String
29post url body = Request "POST" url body []
32-- Performs an HTTP request with the given requests. Produces a signal
33-- that carries the responses.
34send : Signal (Request a) -> Signal (Response String)
35send = Native.HTTP.send
37-- Performs an HTTP GET request with the given urls. Produces a signal
38-- that carries the responses.
39sendGet : Signal String -> Signal (Response String)
40sendGet = send . lift get