Quantcast

How to call api that set headers?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to call api that set headers?

Watt Poosanguansit

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.

--
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to call api that set headers?

Alp Mestanogullari
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 :)

On Wed, Feb 15, 2017 at 2:45 PM, Watt Poosanguansit <[hidden email]> wrote:

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

--
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to call api that set headers?

Watt Poosanguansit
Thanks for your help.  I have got it working now.


On Feb 15, 2017, at 7:04 AM, Alp Mestanogullari <[hidden email]> wrote:

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 :)

On Wed, Feb 15, 2017 at 2:45 PM, Watt Poosanguansit <[hidden email]> wrote:

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

--
Loading...