purescript-httpurple/docs/Examples/BinaryRequest/Main.purs
Connor Prussin 6e886b91ac
Add support for non string requests (#184)
* First version of supporting non-string requests

* Clean up

* Minor cleanup

* Simplify to directly export the stream

* Add nl

* Clean up & add more testing

Co-authored-by: sigma-andex <sigma.andex@pm.me>
2021-11-15 20:02:36 -08:00

25 lines
1.2 KiB
Haskell

module Examples.BinaryRequest.Main where
import Prelude
import Effect.Console as Console
import Node.Buffer (Buffer)
import HTTPure as HTTPure
foreign import sha256sum :: Buffer -> String
-- | Respond with file's sha256sum
router :: HTTPure.Request -> HTTPure.ResponseM
router { body } = HTTPure.toBuffer body >>= sha256sum >>> HTTPure.ok
-- | Boot up the server
main :: HTTPure.ServerM
main =
HTTPure.serve 8080 router do
Console.log $ " ┌─────────────────────────────────────────────────────────┐"
Console.log $ " │ Server now up on port 8080 │"
Console.log $ " │ │"
Console.log $ " │ To test, run: │"
Console.log $ " │ > curl -XPOST --data-binary @circle.png localhost:8080 │"
Console.log $ " │ # => d5e776724dd5... │"
Console.log $ " └─────────────────────────────────────────────────────────┘"