How to call api that set headers?

58 views
Skip to first unread message

Watt Poosanguansit

unread,
Feb 15, 2017, 8:45:54 AM2/15/17
to haskell-servant

I hope you do not mind I ask you here for some help with servant-auth here. I have been trying to work with the example I found there and I am still not able to make post call to


type Unprotected =
      Raw
     :<|> "login"
     :> ReqBody '[JSON] Login
     :> PostNoContent '[JSON] (Headers '[Header "Set-Cookie" SetCookie] NoContent)


login. I keep getting "Only GET or HEAD is supported" when I do a Post call to localhost:7249/login with {"username": "test", "password": "test"} in the body. How could we do a login with the api? I appreciate any help.

Alp Mestanogullari

unread,
Feb 15, 2017, 10:04:41 AM2/15/17
to Watt Poosanguansit, haskell-servant
You have to put the Raw endpoint after the other one. A Raw endpoint matches everything (even if you actually end up sending a 404 in your corresponding handler). You always have to put it last. When no other criterion is available, servant-server's routing mechanism will try to route a request to an API (Endpoint1 :<|> Endpoint2) by first trying Endpoint1, and if _routing_ succeeds you return whatever Endpoint1 returns. Routing always suceeds with Raw, ergo your second endpoint is effectively unreachable. Switch the order of the two and everything should be fine :)

--
You received this message because you are subscribed to the Google Groups "haskell-servant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to haskell-servant+unsubscribe@googlegroups.com.
To post to this group, send email to haskell-servant@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/haskell-servant/7757dbac-d79d-495d-a2cc-a75c335d677f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Alp Mestanogullari

Watt Poosanguansit

unread,
Feb 17, 2017, 2:46:35 AM2/17/17
to Alp Mestanogullari, haskell-servant
Thanks for your help.  I have got it working now.

Reply all
Reply to author
Forward
0 new messages