elm/libraries/Http.elm
Colin Curtin 8db9ccf57e Fix HTTP/JSON
* Elm Http: Signal (lift) was not imported
* Native Http: "Waiting" was not a string.
* Elm Json: find* weren't using the Json Object type (which find was expecting)
* Native Json: Utils was not imported (to use Tuple2)
2013-05-11 13:35:20 -07:00

43 lines
1.4 KiB
Elm

-- A library for asynchronous HTTP requests (AJAX). See the
-- [WebSocket](http://elm-lang.org/docs/WebSocket.elm) library if
-- you have very strict latency requirements.
module Http where
import Native.Http (send)
import Signal (lift)
-- The datatype for responses. Success contains only the returned message.
-- Failures contain both an error code and an error message.
data Response a = Success a | Waiting | Failure Int String
type Request a = {
verb : String,
url : String,
body : a,
headers : [(String,String)]
}
-- Create a customized request. Arguments are request type (get, post, put,
-- delete, etc.), target url, data, and a list of additional headers.
request : String -> String -> String -> [(String,String)] -> Request String
request = Request
-- Create a GET request to the given url.
get : String -> Request String
get url = Request "GET" url "" []
-- Create a POST request to the given url, carrying the given data.
post : String -> String -> Request String
post url body = Request "POST" url body []
-- Performs an HTTP request with the given requests. Produces a signal
-- that carries the responses.
send : Signal (Request a) -> Signal (Response String)
-- Performs an HTTP GET request with the given urls. Produces a signal
-- that carries the responses.
sendGet : Signal String -> Signal (Response String)
sendGet reqs = send (lift get reqs)