As many of you probably do, I wanted to upgrade my Elm application to use the new elm/http 2.0 packages. So today I bit the bullet, and did just that. I thought it might be interesting for others, so here we go.

I used elm/http 1.0, NoRedInk/elm-rails and lukewestby/elm-http-builder throughout the existing code.
This was also an opportunity to streamline this .

elm.json

I moved the existing elm.json out of the way, and proceeded with elm init to make a brand new one.
I did this because changing the file by hand tends to lead to a lot of issues.
I also remove elm-stuff, just to be sure.elm install elm/http (yes! version 2.0), and then installed all my other packages.

Code changes

I used a certain pattern a lot in my code. I would have a function that would return a Http.Request that I would Http.send in another module. It took me a while to find a way to keep this flexibility.

The backend we are using in this app is a Rails application. Rails uses certain conventions, one is that for creating records you use POST, for updating PATCH or PUT and DELETE for destroying. Instead of figuring out how to do this I started using elm-rails (elm 0.17) and later on elm-http-builder.
I switched to elm-http-builder to be able to specify the CSRF token in the header. elm-rails requires me to install an extra npm package to find the token in the Rails-generated HTML. I prefer to pass it to my app as a flag. But still there were some elm-rails calls all over the place.

Remember the functions I used to make that would return a Http.Request and now return a Cmd msg?

load id
|> RemoteData.sendRequest
|> Cmd.map Loaded

now

load id (RemoteData.fromResult >> Loaded)

Returning an Int

EDIT
You may skip the next part, as @hector pointed out to me an Int is valid Json…
So the expect becomes simply expect = Http.expectJson Created Decode.int.
But I’ll leave the code here, maybe somebody will find it interesting
/EDIT

There was still one snag, some of my actions return an integer value only, not a json, just an integer.

Thank you for this post, it was helpful in figuring out how to upgrade to http 2.0. I must say that deleting elm.json and rebuilding it from scratch is a pain when you have even a handful of dependencies and all you need is to update one of them.