ReqBody '[PlainText] Text :> Post '[Pl" /> ReqBody '[PlainText] Text :> Post '[Pl" /> ReqBody '[PlainText] Text :> Post '[Pl"/>

how to get POST data as text in servant

82 Views Asked by At

I want to get raw POST request data in a servant and then parse it by myself:

Servant code:

type API = "reg" 
               :> ReqBody '[PlainText] Text
               :> Post '[PlainText] String
      


server :: Env -> Server API
server env = reg 

  where
    reg d  = do 
               **-- HERE I WANT TO PARSE d MYSELF**
               liftIO $ print "reg!"
               return "reg"

Then I try access with:

curl -i -X POST -H "Content-Type: text/plain;charset-utf8" -data "email=1&name=2&pwd=3" http://localhost:8080/reg

I got

curl: (3) URL rejected: Bad hostname
HTTP/1.1 415 Unsupported Media Type
Transfer-Encoding: chunked
Date: Sun, 11 Feb 2024 11:12:42 GMT
Server: Warp/3.3.31

How to make this work?

I expect the successfull request

0

There are 0 best solutions below