使用以下Scotty端点:
myendpoint :: Text -> ScottyM ()
myendpoint info =
post "/foo/bar/:var" $ do
var :: Text <- param "var"
query :: Query <- jsonData
result <- liftIO $ retrieveResult info var query
json $ result
runApi :: IO ()
runApi = scotty 4602 $ do
myendpoint
例如,如何myendpoint
使用不同的可能输入进行测试
info1 = "foo"
query1 = Query { qParam1 = "foo", qParam2 = "bar" }
var1 = "bar"
expect1 = Result { foo = "foo", bar = "bar" }
res1 = decode $ test_myendpoint info1 query1 var1
res1 `shouldBe` expect1
info2 = "baz"
query2 = Query { qParam1 = "hello", qParam2 = "there" }
var2 = "boo"
expect2 = Result { foo = "biz", bar = "dev" }
res2 = decode $ test_myendpoint info2 query2 var2
res2 `shouldBe` expect2
我很想在另一个线程中简单地运行 API,然后使用一些 JSON 查询端点,但是有没有更简洁的方法来做到这一点?(尽管上述的好处是真正的端到端测试)