fix: migrate to new tooling

This commit is contained in:
2023-12-13 15:51:23 -06:00
parent 611a0be19e
commit 0b38030bf1
59 changed files with 412 additions and 591 deletions

View File

@@ -0,0 +1,48 @@
module Examples.Headers.Main where
import Prelude
import Data.Generic.Rep (class Generic)
import Effect.Aff (Aff)
import Effect.Console (log)
import HTTPurple (Request, ResponseHeaders, Response, ServerM, ok', serve, (!@))
import HTTPurple.Headers (headers)
import Routing.Duplex as RD
import Routing.Duplex.Generic as RG
data Route = SayHello
derive instance Generic Route _
route :: RD.RouteDuplex' Route
route = RD.root $ RG.sum
{ "SayHello": RG.noArgs
}
-- | The headers that will be included in every response.
responseHeaders :: ResponseHeaders
responseHeaders = headers
{ "X-Example": "hello world!"
, "X-Example2": "hello world!"
}
-- | Route to the correct handler
router :: Request Route -> Aff Response
router { headers } = ok' responseHeaders $ headers !@ "X-Input"
-- | Boot up the server
main :: ServerM
main =
serve { hostname: "localhost", port: 10000, onStarted } { route, router }
where
onStarted = do
log " ┌──────────────────────────────────────────────┐"
log " │ Server now up on port 10000 │"
log " │ │"
log " │ To test, run: │"
log " │ > curl -H 'X-Input: test' -v localhost:10000│"
log " │ # => ... │"
log " │ # => ...< X-Example: hello world! │"
log " │ # => ... │"
log " │ # => test │"
log " └──────────────────────────────────────────────┘"

View File

@@ -0,0 +1,18 @@
# Headers Example
This is a basic example of working with headers. It will respond to an HTTP GET
on any url and will read the header 'X-Input' and return the contents in the
response body. It will also return the 'X-Example' response header with the
value 'hello world!'.
To run the example server, run:
```bash
nix-shell --run 'example Headers'
```
Or, without nix:
```bash
spago -x test.dhall run --main Examples.Headers.Main
```