simonh1000 / elm-jwt / Jwt.Http

Authenticated Http requests

get : String -> { url : String, expect : Http.Expect msg } -> Platform.Cmd.Cmd msg

A replacement for Http.get that also takes a token, which is attached to the headers.

getData : String -> Cmd Msg
getData token =
    Jwt.Http.get token
        { url = serverUrl ++ "/api/data"
        , expect = Http.expectJson OnDataResponse dataDecoder
        }

post : String -> { url : String, body : Http.Body, expect : Http.Expect msg } -> Platform.Cmd.Cmd msg

A replacement for Http.post that also takes a token, which is attached to the headers. NOTE that is important to use jsonBody to ensure that the 'application/json' is added to the headers

sendToServer : String -> String -> Json.Decode.Decoder a -> Json.Encode.Value -> Cmd msg
sendToServer token url dec value =
    Jwt.Http.post token
        { url = url
        , body = Http.jsonBody value
        , expect = Http.expectJson ContentResult (phoenixDecoder dec)
        }

put : String -> { url : String, body : Http.Body, expect : Http.Expect msg } -> Platform.Cmd.Cmd msg

Create a PUT command with a token attached to the headers.

delete : String -> { url : String, expect : Http.Expect msg } -> Platform.Cmd.Cmd msg

Create a DELETE command with a token attached to the headers.

is401 : Http.Error -> Basics.Bool

Helper that checks an Http.Error for a 401