Open flip111 opened 6 years ago
Well the way to define routes changed. /echo/regex/{param:^[0-9]+$}
is not supported in that syntax anymore.
I fixed the code, but how to specify the regex now?
{-# LANGUAGE OverloadedStrings #-}
module Main where
import System.Environment
import qualified Web.Scotty as Scotty
import qualified Web.Spock as Spock
import qualified Web.Spock.Config as SpockConfig
main =
do args <- getArgs
let port = 8080
case args of
["scotty"] ->
Scotty.scotty port $
do Scotty.get "/echo/hello-world" $
Scotty.text "Hello World"
Scotty.get "/echo/plain/:param" $
do p <- Scotty.param "param"
Scotty.text p
Scotty.get (Scotty.regex "^/echo/regex/([0-9]+)$") $
do p <- Scotty.param "1"
Scotty.text p
["spock"] -> do
spockCfg <- SpockConfig.defaultSpockCfg () SpockConfig.PCNoDatabase ()
Spock.runSpock port $ Spock.spock spockCfg $
do Spock.get ("echo" Spock.<//> "hello-world") $
Spock.text "Hello World"
Spock.get ("echo" Spock.<//> "plain" Spock.<//> Spock.var) $ \param ->
Spock.text param
Spock.get ("echo" Spock.<//> "regex" Spock.<//> Spock.var) $ \param ->
do Spock.text param
_ -> putStrLn "Usage: ./Spock-scotty-benchmark spock|scotty"
Write a newtype for it and then implement the regex checking using http://hackage.haskell.org/package/http-api-data-0.3.5/docs/Web-Internal-HttpApiData.html#t:FromHttpApiData
The documentation you linked doesn't contain anything about regex. Do you have a recommendation about a regex library? There seem to be quite a few https://wiki.haskell.org/Regular_expressions
I was trying to upgrade the code to the latest versions of this framework. I made some modifications the code compiles but
./bench.sh
givesInvalid http://localhost:8080/echo/plain/hello repsonse! Expected 'hello' got '' (Is the server running?)