{"id":18254745,"url":"https://github.com/fabienhenon/jsonapi-http","last_synced_at":"2026-06-05T11:31:31.685Z","repository":{"id":57674890,"uuid":"207341825","full_name":"FabienHenon/jsonapi-http","owner":"FabienHenon","description":"Make HTTP requests with jsonapi decoding/encoding in Elm","archived":false,"fork":false,"pushed_at":"2021-09-27T15:09:03.000Z","size":26,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-14T08:38:15.904Z","etag":null,"topics":["elm","http","jsonapi","remotedata"],"latest_commit_sha":null,"homepage":null,"language":"Elm","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FabienHenon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-09T15:27:50.000Z","updated_at":"2025-04-17T20:32:31.000Z","dependencies_parsed_at":"2022-09-02T15:01:41.870Z","dependency_job_id":null,"html_url":"https://github.com/FabienHenon/jsonapi-http","commit_stats":null,"previous_names":["calions-app/jsonapi-http"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/FabienHenon/jsonapi-http","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FabienHenon%2Fjsonapi-http","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FabienHenon%2Fjsonapi-http/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FabienHenon%2Fjsonapi-http/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FabienHenon%2Fjsonapi-http/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FabienHenon","download_url":"https://codeload.github.com/FabienHenon/jsonapi-http/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FabienHenon%2Fjsonapi-http/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279018302,"owners_count":26086344,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elm","http","jsonapi","remotedata"],"created_at":"2024-11-05T10:13:25.773Z","updated_at":"2025-10-14T08:38:16.469Z","avatar_url":"https://github.com/FabienHenon.png","language":"Elm","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jsonapi-http\n\n\nMake HTTP requests with jsonapi decoding/encoding in Elm.\n\nThis package makes use of the packages [jsonapi](https://package.elm-lang.org/packages/FabienHenon/jsonapi/latest/) and \n[remotedata](https://package.elm-lang.org/packages/krisajenkins/remotedata/latest/).\n\nYou will be able to send HTTP requests that expect a jsonapi object as a response.\n\n## Getting started\n\nHere is an example of the creation of a post, that expects a post as a return value.\nThe posts we send and receive will follow the jsonapi specification.\n\n```elm\ntype alias User =\n   { id : String\n   , name : String\n   }\n\n\ntype alias Post =\n    { id : String\n    , title : String\n    , body : String\n    , creator : User\n    }\n\n\ntype alias PostPayload =\n    { title : String\n    , body : String\n    }\n\n\ncreatePost : (RemoteData.RemoteData Http.Error.RequestError Post) -\u003e PostPayload -\u003e Cmd msg\ncreatePost msg body =\n    Http.Request.request\n        { headers = []\n        , url = { url = \"/api/post\", method = Http.Methods.POST }\n        , body = encodeBody body\n        , documentDecoder = JsonApi.Decode.resource \"posts\" postDecoder\n        }\n        |\u003e Task.map (RemoteData.map JsonApi.Document.resource)\n        |\u003e Task.perform msg\n\n\nencodeBody : PostPayload -\u003e Json.Encode.Value\nencodeBody body =\n    JsonApi.Encode.Document.build\n        |\u003e JsonApi.Encode.Document.withResource\n            (JsonApi.Resource.build \"posts\"\n                |\u003e JsonApi.Resource.withAttributes\n                    [ ( \"body\", Json.Encode.string body.body )\n                    , ( \"title\", Json.Encode.string body.title )\n                    ]\n            )\n        |\u003e JsonApi.Encode.document\n\n\npostDecoder : JsonApi.Resource.Resource -\u003e Json.Decode.Decoder Post\npostDecoder res =\n    Json.Decode.map4 Post\n        (Json.Decode.succeed (JsonApi.Resource.id res))\n        (Json.Decode.field \"title\" Json.Decode.string)\n        (Json.Decode.field \"body\" Json.Decode.string)\n        (JsonApi.Decode.relationship \"creator\" res User.userDecoder)\n\n\nuserDecoder : JsonApi.Resource.Resource -\u003e Json.Decode.Decoder User\nuserDecoder res = \n    Json.Decode.map2 User\n        (Json.Decode.succeed (JsonApi.Resource.id res))\n        (Json.Decode.field \"name\" Json.Decode.string)\n```\n\nHere is how to use the functions defined above to create a new post and retrieve this\nnewly created post from the server.\n\n```elm\ntype Msg =\n    OnPostCreated (RemoteData.RemoteData Http.Error.RequestError Post)\n\n\ntype alias Model =\n    { post : RemoteData.RemoteData Http.Error.RequestError Post }\n\n\nnewPost : PostPayload\nnewPost =\n    { title = \"My new post\"\n    , body = \"This is a new post\"\n    }\n\n\ninit : ( Model, Cmd Msg )\ninit =\n    ( { post = RemoteData.Loading }\n    , createPost OnPostCreated newPost\n    )\n\n\nupdate : Msg -\u003e Model -\u003e ( Model, Cmd Msg )\nupdate msg model =\n    case msg of\n        OnPostCreated post -\u003e\n            ( { model | post = post }\n            , Cmd.none\n            )\n\n\nview : Model -\u003e Html Msg\nview model =\n    case model.post of\n        RemoteData.NotAsked -\u003e\n            text \"The post will be created soon\"\n\n        RemoteData.Loading -\u003e\n            text \"Still a few seconds to wait!\"\n\n        RemoteData.Failure error -\u003e\n            viewError error\n\n        RemoteData.Success post -\u003e\n            div []\n                [ div [ class \"post-title\" ] [ text post.title ]\n                , div [ class \"post-body\" ] [ text post.body ]\n                , div [ class \"post-creator\" ] [ text post.creator.name ]\n                ]\n\n\nviewError : Http.Error.RequestError -\u003e Html Msg\nviewError error =\n    case error of\n        Http.Error.HttpError httpError -\u003e\n            text \"This is a HTTP error as we already know them...\"\n\n        Http.Error.CustomError msg -\u003e\n            text (\"Custom error \" ++ msg)\n\n        Http.Error.JsonApiError errors -\u003e\n            text \"This is an error coming from the jsonapi paylaod\"\n\n\nsubscriptions : Model -\u003e Sub Msg\nsubscriptions = \n    Sub.none\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffabienhenon%2Fjsonapi-http","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffabienhenon%2Fjsonapi-http","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffabienhenon%2Fjsonapi-http/lists"}