本文整理汇总了Scala中play.api.http.HttpVerbs类的典型用法代码示例。如果您正苦于以下问题:Scala HttpVerbs类的具体用法?Scala HttpVerbs怎么用?Scala HttpVerbs使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HttpVerbs类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: CommentsAction
//设置package包名称以及导入依赖的类
package v1.news
import javax.inject.Inject
import play.api.http.HttpVerbs
import play.api.i18n.{Messages, MessagesApi}
import play.api.mvc._
import play.api.http.HeaderNames
import scala.concurrent.{ExecutionContext, Future}
class CommentsAction @Inject()(messagesApi: MessagesApi)(
implicit ec: ExecutionContext)
extends ActionBuilder[CommentsRequest]
with HttpVerbs {
type CommentsRequestBlock[A] = CommentsRequest[A] => Future[Result]
private val logger = org.slf4j.LoggerFactory.getLogger(this.getClass)
override def invokeBlock[A](request: Request[A],
block: CommentsRequestBlock[A]): Future[Result] = {
if (logger.isTraceEnabled()) {
logger.trace(s"invokeBlock: request = $request")
}
val messages = messagesApi.preferred(request)
val future = block(new CommentsRequest(request, messages))
future.map { result =>
request.method match {
case GET | HEAD =>
result.withHeaders("Cache-Control" -> s"max-age: 100")
case other =>
result
}
}
}
}
示例2: PostAction
//设置package包名称以及导入依赖的类
package v1.post
import javax.inject.Inject
import play.api.http.HttpVerbs
import play.api.i18n.{Messages, MessagesApi}
import play.api.mvc._
import scala.concurrent.{ExecutionContext, Future}
class PostAction @Inject()(messagesApi: MessagesApi)(
implicit ec: ExecutionContext)
extends ActionBuilder[PostRequest]
with HttpVerbs {
type PostRequestBlock[A] = PostRequest[A] => Future[Result]
private val logger = org.slf4j.LoggerFactory.getLogger(this.getClass)
override def invokeBlock[A](request: Request[A],
block: PostRequestBlock[A]): Future[Result] = {
if (logger.isTraceEnabled()) {
logger.trace(s"invokeBlock: request = $request")
}
val messages = messagesApi.preferred(request)
val future = block(new PostRequest(request, messages))
future.map { result =>
request.method match {
case GET | HEAD =>
result.withHeaders("Cache-Control" -> s"max-age: 100")
case other =>
result
}
}
}
}
示例3: PlaySpecApplication
//设置package包名称以及导入依赖的类
package common
import org.scalatestplus.play.PlaySpec
import play.api.http.{ HeaderNames, HttpProtocol, HttpVerbs, Status }
import play.api.test._
class PlaySpecApplication extends PlaySpec
with PlayRunners
with HeaderNames
with Status
with HttpProtocol
with DefaultAwaitTimeout
with ResultExtractors
with Writeables
with RouteInvokers
with FutureAwaits
with HttpVerbs
示例4: Setting
//设置package包名称以及导入依赖的类
package httpmock
import play.api.http.HttpVerbs
import play.api.mvc._
import play.api.routing.Router.Routes
import HttpMock.implementedMethods
final case class Setting(
port: Int = 0,
methods: Set[HttpMethod] = implementedMethods,
handler: PartialFunction[RequestHeader, Result] = PartialFunction.empty
) {
val logs = new AccessLogQueue()
private[this] def routeFor(method: HttpMethod): Routes = {
import play.api.routing.sird
import play.api.routing.sird.UrlContext
def action(r: RequestHeader) = Action { request =>
if (r.method == HttpVerbs.POST || r.method == HttpVerbs.PUT) {
request.body match {
case AnyContentAsRaw(raw) => logs.add(r, raw.asBytes().map(ArrayByte))
case _ => logs.add(r)
}
} else {
logs.add(r)
}
handler.applyOrElse[RequestHeader, Result](r, r => Results.Ok(r.toString))
}
// TODO: add query parameters and request body to logs
method match {
case GET => { case r @ sird.GET(p"/$path*") => action(r) }
case POST => { case r @ sird.POST(p"/$path*") => action(r) }
case PUT => { case r @ sird.PUT(p"/$path*") => action(r) }
case PATCH => { case r @ sird.PATCH(p"/$path*") => action(r) }
case DELETE => { case r @ sird.DELETE(p"/$path*") => action(r) }
case HEAD => { case r @ sird.HEAD(p"/$path*") => action(r) }
case OPTIONS => { case r @ sird.OPTIONS(p"/$path*") => action(r) }
}
}
def routes: Routes = methods.map(routeFor).foldLeft(PartialFunction.empty: Routes) { _ orElse _ }
}
object Setting {
implicit def toHttpMockDown(setting: Setting): HttpMockDown = HttpMockDown(setting, setting.port)
}
示例5: UserRequest
//设置package包名称以及导入依赖的类
package v1.user
import javax.inject.Inject
import play.api.http.HttpVerbs
import play.api.i18n.{Messages, MessagesApi}
import play.api.mvc._
import scala.concurrent.{ExecutionContext, Future}
class UserRequest[A](request: Request[A], val messages: Messages)
extends WrappedRequest(request)
class UserAction @Inject() (messagesApi: MessagesApi)
(
implicit ec: ExecutionContext
) extends ActionBuilder[UserRequest]
with HttpVerbs {
type UserRequestBlock[A] = UserRequest[A] => Future[Result]
private val logger = org.slf4j.LoggerFactory.getLogger(this.getClass)
override def invokeBlock[A](request: Request[A],
block: UserRequestBlock[A]): Future[Result] = {
if (logger.isTraceEnabled()) {
logger.trace(s"invokeBlock: request = $request")
}
val messages = messagesApi.preferred(request)
val future = block(new UserRequest(request, messages))
future.map { result =>
request.method match {
case GET | HEAD =>
result.withHeaders("Cache-Control" -> s"max-age: 100")
case other =>
result
}
}
}
}
示例6: SignatureAction
//设置package包名称以及导入依赖的类
package v1.signature
import javax.inject.Inject
import play.api.http.HttpVerbs
import play.api.i18n.{Messages, MessagesApi}
import play.api.mvc._
import scala.concurrent.{ExecutionContext, Future}
class SignatureAction @Inject()(messagesApi: MessagesApi)(
implicit ec: ExecutionContext)
extends ActionBuilder[SignatureRequest]
with HttpVerbs {
type PostRequestBlock[A] = SignatureRequest[A] => Future[Result]
private val logger = org.slf4j.LoggerFactory.getLogger(this.getClass)
override def invokeBlock[A](request: Request[A],
block: PostRequestBlock[A]): Future[Result] = {
if (logger.isTraceEnabled()) {
logger.trace(s"invokeBlock: request = $request")
}
val messages = messagesApi.preferred(request)
val future = block(new SignatureRequest(request, messages))
future.map { result =>
request.method match {
case GET | HEAD =>
result.withHeaders("Cache-Control" -> s"max-age: 100")
case other =>
result
}
}
}
}
示例7: TodoRequest
//设置package包名称以及导入依赖的类
package todo
import javax.inject.{Inject, Singleton}
import play.api.http.HttpVerbs
import play.api.mvc.{ActionBuilder, Request, Result, WrappedRequest}
import scala.concurrent.{ExecutionContext, Future}
class TodoRequest[A](request: Request[A])
extends WrappedRequest(request)
@Singleton
class TodoAction @Inject()(implicit ec: ExecutionContext)
extends ActionBuilder[TodoRequest]
with HttpVerbs {
override def invokeBlock[A](request: Request[A], block: (TodoRequest[A]) => Future[Result]) = {
val future = block(new TodoRequest(request))
future.map(result => {
request.method match {
case GET | HEAD =>
result.withHeaders("Cache-Control" -> s"max-age: 1000")
case other =>
result
}
})
}
}
示例8: PostAction
//设置package包名称以及导入依赖的类
package v1.post
import javax.inject.Inject
import play.api.http.HttpVerbs
import play.api.i18n.{Messages, MessagesApi}
import play.api.mvc._
import scala.concurrent.{ExecutionContext, Future}
class PostAction @Inject()(messagesApi: MessagesApi)
(implicit ec: ExecutionContext)
extends ActionBuilder[PostRequest] with HttpVerbs {
type PostRequestBlock[A] = PostRequest[A] => Future[Result]
private val logger = org.slf4j.LoggerFactory.getLogger(this.getClass)
override def invokeBlock[A](request: Request[A], block: PostRequestBlock[A]): Future[Result] = {
if (logger.isTraceEnabled()) {
logger.trace(s"invokeBlock: request = $request")
}
val messages = messagesApi.preferred(request)
val future = block(new PostRequest(request, messages))
future.map { result =>
request.method match {
case GET | HEAD =>
result.withHeaders("Cache-Control" -> s"max-age: 100")
case other =>
result
}
}
}
}
示例9: BobRequest
//设置package包名称以及导入依赖的类
package v1.bob
import javax.inject.Inject
import play.api.http.HttpVerbs
import play.api.i18n.{Messages, MessagesApi}
import play.api.mvc._
import scala.concurrent.{ExecutionContext, Future}
class BobRequest[A](request: Request[A], val messages: Messages) extends WrappedRequest(request)
class BobAction @Inject()(messagesApi: MessagesApi)
(implicit ec: ExecutionContext)
extends ActionBuilder[BobRequest] with HttpVerbs {
type SlackRequestBlock[A] = BobRequest[A] => Future[Result]
private val logger = org.slf4j.LoggerFactory.getLogger(this.getClass)
override def invokeBlock[A](request: Request[A], block: SlackRequestBlock[A]): Future[Result] = {
if (logger.isTraceEnabled()) {
logger.trace(s"invokeBlock: request = $request")
}
val messages = messagesApi.preferred(request)
val future = block(new BobRequest(request, messages))
future.map { result =>
request.method match {
case GET | HEAD =>
result.withHeaders("Cache-Control" -> s"max-age: 100")
case other =>
result
}
}
}
}