我正在使用HTTP4S,并且webapp正在码头运行。 Web应用程序文件配置为:
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<servlet>
<servlet-name>user-svc</servlet-name>
<servlet-class>io.databaker.UserSvcServlet</servlet-class>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>user-svc</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
可用的URI是:
object UserSvcRoutes {
def helloWorldRoutes[F[_]: Sync](H: HelloWorld[F]): HttpRoutes[F] = {
val dsl = new Http4sDsl[F]{}
import dsl._
HttpRoutes.of[F] {
case GET -> Root =>
Ok("Example")
case GET -> Root / "hello" / name =>
for {
greeting <- H.hello(HelloWorld.Name(name))
resp <- Ok(greeting)
} yield resp
}
}
}
当我打电话给http://localhost:8080/时,我得到了:
[Http4sServlet
最近被抽象化,Http4sServlet
和BlockingHttp4sServlet
提供了两个具体的实现。
您可以通过更改BlockingHttp4sServlet
来扩展其中任何一个来使示例工作:
AsyncHttp4sServlet