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,49 @@
module Examples.QueryParameters.Main where
import Prelude
import Data.Generic.Rep (class Generic)
import Data.Maybe (Maybe(..))
import Effect (Effect)
import Effect.Aff (Aff)
import Effect.Class.Console (log)
import HTTPurple (Request, Response, ServerM, notFound, ok, serve)
import Routing.Duplex (RouteDuplex')
import Routing.Duplex as RD
import Routing.Duplex.Generic as G
data Route = Route { foo :: Boolean, bar :: Maybe String, baz :: Maybe String }
derive instance Generic Route _
route :: RouteDuplex' Route
route = RD.root $ G.sum
{ "Route": RD.params { foo: RD.flag <<< RD.string, bar: RD.optional <<< RD.string, baz: RD.optional <<< RD.string }
}
-- | Specify the routes
router :: Request Route -> Aff Response
router { route: (Route { foo: true }) } = ok "foo"
router { route: (Route { bar: Just "test" }) } = ok "bar"
router { route: (Route { bar: Just _ }) } = ok ""
router { route: Route { baz: Just baz } } = ok $ baz
router _ = notFound
-- | Boot up the server
main :: ServerM
main =
serve { hostname: "localhost", port: 10000, onStarted } { route, router }
where
onStarted :: Effect Unit
onStarted = do
log " ┌───────────────────────────────────────┐"
log " │ Server now up on port 10000 │"
log " │ │"
log " │ To test, run: │"
log " │ > curl localhost:10000?foo │"
log " │ # => foo │"
log " │ > curl localhost:10000?bar=test │"
log " │ # => bar │"
log " │ > curl localhost:10000?baz=<anything>│"
log " │ # => <anything> │"
log " └───────────────────────────────────────┘"

View File

@@ -0,0 +1,18 @@
# Query Parameters Example
This is a basic example that demonstrates working with URL query parameters. It
includes an example of routing based on the _existence_ of a query parameter, an
example of routing based on the _value_ of a given query parameter, and an
example where the response is driven by the contents of a query parameter.
To run the example server, run:
```bash
nix-shell --run 'example QueryParameters'
```
Or, without nix:
```bash
spago -x test.dhall run --main Examples.QueryParameters.Main
```