This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.
We were not able to find the expected elm-package.json file at this tag.
Tag 7.0.0
Committed At 2019-05-01 03:28:01 UTC

Modules

    README

    elm-http-builder

    Pipeable functions for building HTTP requests

    import Http
    import HttpBuilder
    import Json.Decode as Decode
    import Json.Encode as Encode
    import Url.Builder as UrlBuilder
    
    
    type Status a = Loading | Loaded a | Failure
    
    
    type alias Model = { items : Status (List String) }
    
    
    itemsDecoder : Decode.Decoder (List String)
    itemsDecoder =
        Decode.list Decode.string
    
    
    itemEncoder : String -> Encode.Value
    itemEncoder item =
        Encode.object
            [ ("item", Encode.string item) ]
    
    
    {-| addItem will send a post request to
    `"http://example.com/api/items?hello=world"` with the given JSON body and a
    custom header. It'll try to decode with `itemsDecoder`.
    
    -}
    addItem : String -> Cmd Msg
    addItem item =
        UrlBuilder.crossOrigin
            "http://example.com"
            [ "api", "items" ]
            [ UrlBuilder.string "hello" "world" ]
            |> HttpBuilder.post
            |> HttpBuilder.withHeader "X-My-Header" "Some Header Value"
            |> HttpBuilder.withJsonBody (itemEncoder item)
            |> HttpBuilder.withTimeout 10000
            |> HttpBuilder.withExpect (Http.expectJson GotItem itemsDecoder)
            |> HttpBuilder.request
    
    
    type Msg = GotItem (Result Http.Error (List String))
    
    
    update : Msg -> Model -> ( Model, Cmd Msg )
    update msg model =
        case msg of
            GotItem (Ok items) ->
              ( { model | items = Loaded items }
              , Cmd.none
              )
    
            GotItem (Err err) ->
              ( { model | items = Failure } , Cmd.none)