Hi, in case it may be of help, I just did a small test elm project using 
web api which is available at this repo 
<https://github.com/mpizenberg/elm_api_test>.
Basically it was to test a way to use api (and authentified api using JWT) 
that I adapted from a 0.17 tutorial available on the Auth0 website 
<https://auth0.com/blog/creating-your-first-elm-app-part-1/>.

On Wednesday, January 18, 2017 at 3:22:23 PM UTC+1, [email protected] wrote:
>
> I'm trying to use elm-lang/http without success so far. I want to address 
> an API with a POST request via JSON. All my efforts so far result in having 
> the wrong headers.
>
> There are two things I've tried in the following: in both cases the server 
> tells me that it wasn't a POST request but OPTIONS.
>
> I've tried using "Http.post":
>
> jsonify : String -> Http.Body
> jsonify str =
>     Http.jsonBody <| Encode.object [("sentiment", Encode.string str)]
>
>
> decodeJson : Decode.Decoder String
> decodeJson =
>     Decode.map2 (\classification status -> classification)
>         (Decode.field "classification" Decode.string)
>         (Decode.field "status" Decode.int)
>
>
> fetchSentiment : String -> Cmd Msg
> fetchSentiment sentiment =
>     Http.send Fetch (Http.post (jsonify sentiment) decodeJson)
>
> and a custom request:
>
> fetchSentiment : String -> Cmd Msg
> fetchSentiment sentiment =
>     Http.send Fetch (postSentiment sentiment decodeJson)
>
> postSentiment : String -> Decode.Decoder String -> Http.Request String
> postSentiment sentiment decoder =
>     Http.request
>         { method = "POST"
>         , headers = [(Http.header "Content-Type" "application/json")]
>         , url = "http://127.0.0.1:5000/sentiment";
>         , body = (jsonify sentiment)
>         , expect = Http.expectJson decoder
>         , timeout = Nothing
>         , withCredentials = False
>         }
>
> Is my problem related to the code above, and if so, how can I fix it?
>
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to