mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-19 02:27:03 +00:00
49 lines
1.1 KiB
Elm
49 lines
1.1 KiB
Elm
module HttpUtil exposing (delete, errorString, patch)
|
|
|
|
import Http
|
|
|
|
|
|
delete : (Result Http.Error () -> msg) -> String -> Cmd msg
|
|
delete msg url =
|
|
Http.request
|
|
{ method = "DELETE"
|
|
, headers = []
|
|
, url = url
|
|
, body = Http.emptyBody
|
|
, expect = Http.expectWhatever msg
|
|
, timeout = Nothing
|
|
, tracker = Nothing
|
|
}
|
|
|
|
|
|
patch : (Result Http.Error () -> msg) -> String -> Http.Body -> Cmd msg
|
|
patch msg url body =
|
|
Http.request
|
|
{ method = "PATCH"
|
|
, headers = []
|
|
, url = url
|
|
, body = body
|
|
, expect = Http.expectWhatever msg
|
|
, timeout = Nothing
|
|
, tracker = Nothing
|
|
}
|
|
|
|
|
|
errorString : Http.Error -> String
|
|
errorString error =
|
|
case error of
|
|
Http.BadUrl str ->
|
|
"Bad URL: " ++ str
|
|
|
|
Http.Timeout ->
|
|
"HTTP timeout"
|
|
|
|
Http.NetworkError ->
|
|
"HTTP Network error"
|
|
|
|
Http.BadStatus res ->
|
|
"Bad HTTP status: " ++ String.fromInt res
|
|
|
|
Http.BadBody msg ->
|
|
"Bad HTTP body: " ++ msg
|