Skip to content
forked from elm/http

Make HTTP requests in Elm (with rate limiting or progress tracking)

License

Notifications You must be signed in to change notification settings

mniessner/forward-http

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HTTP in Elm

Make HTTP requests in Elm.

import Http
import Json.Decode as Decode


-- GET A STRING

getWarAndPeace : Http.Request String
getWarAndPeace =
  Http.getString "https://example.com/books/war-and-peace"


-- GET JSON

getMetadata : Http.Request Metadata
getMetadata =
  Http.get "https://example.com/books/war-and-peace/metadata" decodeMetadata

type alias Metadata =
  { author : String
  , pages : Int
  }

decodeMetadata : Decode.Decoder Metadata
decodeMetadata =
  Decode.map2 Metadata
    (Decode.field "author" Decode.string)
    (Decode.field "pages" Decode.int)


-- SEND REQUESTS

type Msg
  = LoadMetadata (Result Http.Error Metadata)

send : Cmd Msg
send =
  Http.send LoadMetadata getMetadata

Examples

Learn More

To understand how HTTP works in Elm, check out:

About

Make HTTP requests in Elm (with rate limiting or progress tracking)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Elm 77.4%
  • JavaScript 22.6%