2
我的Elm程序使用http.get
的代碼(摘錄)正常工作,但我不得不將其更改爲自定義請求以在頭中指定JWT,並且由於類型不匹配而出現以下錯誤。在Elm中指定Http頭
我想我需要將request
的類型更改爲Http.Request (List QFields)
,但不知道如何去做。顯然,我不能讓它像{ verb = "Get" ...} decoder
,因爲{ verb ... }
是不是一個函數。
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
}