用Scala实现简单的Web和API服务器( 五 )

$ ./mill -w app.runBackground

该命令将在后台运行Cask Web服务器,同时监视文件系统,如果文件发生了变化,则重启服务器。然后我们可以使用浏览器浏览服务器,默认网址是localhost:8080:

用Scala实现简单的Web和API服务器

在/do-thing上还有个POST端点,可以在另一个终端上使用curl来访问:

$ curl -X POST --data hello http://localhost:8080/do-thing

olleh

可见,它接受数据hello,然后将反转的字符串返回给客户端。

然后可以运行app/test/src/ExampleTests.scala中的自动化测试:

$ ./mill clean app.runBackground # stop the webserver running in the background

$ ./mill app.test

[50/56] app.test.compile

推荐阅读