Skip to content
Make HTTP requests in Elm
Elm JavaScript
Branch: master
Clone or download
evancz Merge pull request #48 from gdamjan/master
Origin instead of Host
Latest commit 615275c Nov 19, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Origin instead of Host Nov 17, 2018
.gitignore Initial commit with draft API Oct 4, 2016
LICENSE Initial commit with draft API Oct 4, 2016
README.md Update README for the latest API Nov 9, 2018
elm.json

README.md

HTTP

Make HTTP requests in Elm. Talk to servers.

I very highly recommend reading through The Official Guide to understand how to use this package!

Examples

Here are some commands you might create to send HTTP requests with this package:

import Http
import Json.Decode as D

type Msg
  = GotBook (Result Http.Error String)
  | GotItems (Result Http.Error (List String))

getBook : Cmd Msg
getBook =
  Http.get
    { url = "https://elm-lang.org/assets/public-opinion.txt"
    , expect = Http.expectString GotBook
    }

fetchItems : Cmd Msg
fetchItems =
  Http.post
    { url = "https://example.com/items.json"
    , body = Http.emptyBody
    , expect = Http.expectJson GotItems (D.list (D.field "name" D.string))
    }

But again, to really understand what is going on here, read through The Official Guide. It has sections describing how HTTP works and how to use it with JSON data. Reading through will take less time overall than trying to figure everything out by trial and error!

You can’t perform that action at this time.