My Elm program works fine with the code (excerpt) below using http.get
, but I had to changed it to a custom request to specify JWT in the header, and I get the following error due to type mismatch.
I think I need to change the type of request
to Http.Request (List QFields)
but not sure how to. Apparently, I can't make it like { verb = "Get" ...} decoder
because { verb ... }
is not a function.
The 2nd argument to function `send` is causing a mismatch.
264| Http.send FetchHNTopStories request
^^^^^^^
Function `send` is expecting the 2nd argument to be:
Http.Request (List QFields)
But it is:
Request
<Working code>
request : Http.Request (List QFields)
request =
let
decoder =
JD.at [ "data", "qQry" ] <|
JD.list qDecoder
in
Http.get ("http://localhost:3000/graphql?query=" ++ encoded) decoder
type Msg
= SendMessage
| FetchHNTopStories (Result Http.Error (List QFields))
...
initModel : Taco -> ( Model, Cmd Msg )
initModel taco =
let
startModel = { newMessage = ""
}
cmd = Http.send FetchHNTopStories request
in
( startModel
! [cmd]
)
<Changed code - Not working>
request : Request
request =
let
decoder =
JD.at [ "data", "Qry" ] <|
JD.list qDecoder
headers= [
("Authorization","Bearer eyJhbGciOiJIUzUxM...kv6TGw7H1GX2g")
]
in
{ verb = "GET"
, headers = headers
, url = url
, body = Http.emptyBody
, expect = Http.expectJson decoder
}
Select the web site where you want to add the custom HTTP response header. In the web site pane, double-click HTTP Response Headers in the IIS section. In the actions pane, select Add. In the Name box, type the custom HTTP header name.
There are many uses for custom headers and they are quite commonly used. Even if you aren't using a CDN or haven't specifically defined any custom HTTP headers on your origin server, you may still be sending responses with custom headers.
In the Home pane, double-click HTTP Response Headers. In the HTTP Response Headers pane, click Add... in the Actions pane. In the Add Custom HTTP Response Header dialog box, set the name and value for your custom header, and then click OK.
If I understand correctly, you need to use Http.request
, instead of Http.get
, and supply it a valid record, like this:
request : Http.Request (List QFields)
request =
let
decoder =
JD.at [ "data", "Qry" ] <|
JD.list qDecoder
headers =
[ ( "Authorization", "Bearer eyJhbGciOiJIUzUxM...kv6TGw7H1GX2g" )
]
in
Http.request -- This line is missing from your code
{ method = "GET"
, headers = headers
, url = url
, body = Http.emptyBody
, expect = Http.expectJson decoder
, timeout = Nothing
, withCredentials = False
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With