Created
January 19, 2018 19:30
-
-
Save anttti/9e1fbf760243e275382803dee3fe5a36 to your computer and use it in GitHub Desktop.
Encode object and array to JSON body for POSTing in Elm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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