Scott Nimrod
Scott Nimrod

Reputation: 11570

What argument is Http.Request missing?

I'm trying to create an Http.Request value:

request : Http.Request
request =
    { verb = "POST"
    , headers =
        [ ( "Origin", "http://elm-lang.org" )
        , ( "Access-Control-Request-Method", "POST" )
        , ( "Access-Control-Request-Headers", "X-Custom-Header" )
        ]
    , url = url
    , body = body
    }

The code is embedded in the function below:

tryRegister : Form -> (Result Http.Error JsonProfile -> msg) -> Cmd msg
tryRegister form msg =
    let
        url =
            baseUrl ++ "register"

        body =
            encodeRegistration form |> Http.jsonBody

        request : Http.Request
        request =
            { verb = "POST"
            , headers =
                [ ( "Origin", "http://elm-lang.org" )
                , ( "Access-Control-Request-Method", "POST" )
                , ( "Access-Control-Request-Headers", "X-Custom-Header" )
                ]
            , url = url
            , body = body
            }
    in
        Http.send msg request

I receive the following error:

Type Http.Request has too few arguments. - Expecting 1, but got 0.

What argument is Http.Request missing?

Appendix:

http://package.elm-lang.org/packages/evancz/elm-http/3.0.1/Http

Upvotes: 0

Views: 678

Answers (2)

Jesse
Jesse

Reputation: 2908

The evancz/elm-http package is deprecated, you are probably actually using elm-lang/http so you're looking at the wrong documentation.

To construct a Http.Request using elm-lang/http you need to call the Http.request function and pass it a record describing the request. http://package.elm-lang.org/packages/elm-lang/http/1.0.0/Http#request

Additionally you can't actually set the 'Origin' header for a request from within the browser this means you'll won't need to set any headers at all and can just use the Http.post helper function http://package.elm-lang.org/packages/elm-lang/http/1.0.0/Http#post

Upvotes: 2

Chad Gilbert
Chad Gilbert

Reputation: 36385

Your appendix link is to an old version of the Http package. The new package is elm-lang/http. The type parameter that Request expects is the type to use in a successful response, which in your case looks like it should be JsonProfile.

Upvotes: 3

Related Questions