Skip to content

Instantly share code, notes, and snippets.

@anttti
Created January 19, 2018 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anttti/9e1fbf760243e275382803dee3fe5a36 to your computer and use it in GitHub Desktop.
Save anttti/9e1fbf760243e275382803dee3fe5a36 to your computer and use it in GitHub Desktop.
Encode object and array to JSON body for POSTing in Elm
getWeeklyReports : Cmd Msg
getWeeklyReports =
let
url =
"http://localhost:3001/engagement"
body =
Http.jsonBody <|
Encode.object
[ ( "groupNames", Encode.string "Tammerforce" )
, ( "dates", Encode.list (List.map Encode.string [ "2017-12-01", "2018-01-01" ]) )
]
headers =
[ Http.header "Authorization" "Bearer TOKEN" ]
request =
Http.request
{ method = "POST"
, headers = headers
, url = url
, body = body
, expect = Http.expectJson decodeWeeklyReports
, timeout = Nothing
, withCredentials = False
}
in
Http.send ReceiveWeeklyReports request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment