purescript-httpurple/docs/Examples/Post/Main.purs

32 lines
1002 B
Haskell
Raw Normal View History

2017-10-26 21:19:30 +00:00
module Examples.Post.Main where
2017-07-18 17:09:03 +00:00
import Prelude
import Effect.Console (log)
import HTTPure
( Request
, ResponseM
, ServerM
, Method(Post)
, serve
, ok
, notFound
, toString
)
2017-07-18 17:09:03 +00:00
-- | Route to the correct handler
router :: Request -> ResponseM
router { body, method: Post } = toString body >>= ok
router _ = notFound
2017-07-18 17:09:03 +00:00
-- | Boot up the server
main :: ServerM
main =
serve 8080 router do
log " ┌───────────────────────────────────────────┐"
log " │ Server now up on port 8080 │"
log " │ │"
log " │ To test, run: │"
log " │ > curl -XPOST --data test localhost:8080 │"
log " │ # => test │"
log " └───────────────────────────────────────────┘"