This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.
HTTP server negotiation for JSON API-compliant servers.
version 2.0.0
license BSD3
native-modules False
elm-version 0.18.0 <= v < 0.19.0
Tag 2.0.1
Committed At 2017-06-15 18:14:14 UTC
noahzgordon/elm-jsonapi 2.0.3 <= v < 3.0.0 3.0.0-pre.upgrade
elm-lang/http 1.0.0 <= v < 2.0.0 1.0.0
elm-lang/core 5.0.0 <= v < 6.0.0 5.1.1

Modules

README

elm-jsonapi-http

HTTP negotiation with JSON API-compliant servers. Intended for use with elm-jsonapi.

See the documentation at: http://package.elm-lang.org/packages/noahzgordon/elm-jsonapi-http/latest

Usage

For a live usage example, see the /example directory in the project repo.

Note: The example app requires you to run a Sinatra server, meaning you will need Ruby and Rack installed.

  1. Compile the elm file: cd example && elm make Main.elm
  2. Open the resulting html file [open|tee|firefox] index.html
  3. Run the sinatra server (and make sure it runs on port 9292 if that's not your default): rackup -p 9292
-- from `noahzgordon/elm-jsonapi`
import JsonApi.Resources
-- from `noahzgordon/elm-jsonapi-http`
import JsonApi.Http

type alias Model =
    { protagonist : Maybe Character
    }


type alias Character =
    { firstName : String
    , lastName : String
    }


characterDecoder : Json.Decode.Decoder Character
characterDecoder =
    Json.Decode.object2 Character
        ("first-name" := Json.Decode.string)
        ("last-name" := Json.Decode.string)


getProtagonist : Cmd Message
getProtagonist =
    JsonApi.Http.getPrimaryResource "http://localhost:9292/luke"
        |> Task.perform ProtagonistFailedToLoad ProtagonistLoaded


update message model =
    case message of
        ProtagonistLoaded resource ->
            { model | protagonist = JsonApi.Resources.attributes characterDecoder resource |> Result.toMaybe } ! []

        ProtagonistFailedToLoad e ->
            Debug.log ("Remember to start the server on port 9292! " ++ toString e) (model ! [])