本文整理汇总了Scala中play.api.routing.Router.Routes类的典型用法代码示例。如果您正苦于以下问题:Scala Routes类的具体用法?Scala Routes怎么用?Scala Routes使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Routes类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: UserRouter
//设置package包名称以及导入依赖的类
package v1.user
import javax.inject.Inject
import play.api.routing.Router.Routes
import play.api.routing.SimpleRouter
import play.api.routing.sird._
class UserRouter @Inject()(controller: UserController)
extends SimpleRouter {
var prefix = "/v1/users"
def link(id: UserId): String = {
import com.netaporter.uri.dsl._
val url = prefix / id.toString
url.toString()
}
override def routes: Routes = {
case GET(p"/") =>
controller.index
case POST(p"/") =>
controller.process
case GET(p"/$id") =>
controller.show(id)
}
}
示例2: OrganisationRouter
//设置package包名称以及导入依赖的类
package controllers.organisations //Xolela Masebeni(213160447) [email protected]
import javax.inject.Inject
import play.api.routing.Router.Routes
import play.api.routing.SimpleRouter
import play.api.routing.sird._
class OrganisationRouter @Inject()
(mail: OrganisationController)
extends SimpleRouter {
override def routes: Routes = {
case GET(p"/organisation/$org") =>
mail.getOrganisation(org)
case POST(p"/organisation/create") =>
mail.createOrUpdate
}
}
示例3: UtilRouter
//设置package包名称以及导入依赖的类
package controllers.common.util
import javax.inject.Inject
import play.api.routing.Router.Routes
import play.api.routing.SimpleRouter
import play.api.routing.sird._
class UtilRouter @Inject()
(mail: MailController)
extends SimpleRouter {
override def routes: Routes = {
case GET(p"/mail/$org") =>
mail.getMail(org)
case POST(p"/mail/create") =>
mail.createOrUpdate
}
}
示例4: PostRouter
//设置package包名称以及导入依赖的类
package v1.post
import javax.inject.Inject
import play.api.routing.Router.Routes
import play.api.routing.SimpleRouter
import play.api.routing.sird._
class PostRouter @Inject()(controller: PostController)
extends SimpleRouter {
val prefix = "/v1/posts"
def link(id: PostId): String = {
import com.netaporter.uri.dsl._
val url = prefix / id.toString
url.toString()
}
override def routes: Routes = {
case GET(p"/") =>
controller.index
case POST(p"/") =>
controller.process
case GET(p"/$id") =>
controller.show(id)
}
}
示例5: LocationRouter
//设置package包名称以及导入依赖的类
package controllers.location
import javax.inject.Inject
import play.api.routing.Router.Routes
import play.api.routing.SimpleRouter
import play.api.routing.sird._
class LocationRouter @Inject()(addressTypeCtrl: AddressTypeCtrl,
locationTypeCtrl: LocationTypeCtrl,
contactTypeCtrl: ContactTypeCtrl)
extends SimpleRouter {
override def routes: Routes = {
//address
case GET(p"/addresstype/all") =>
addressTypeCtrl.getAll
case GET(p"/addresstype/$id") =>
addressTypeCtrl.getById(id)
case POST(p"/addresstype/create") =>
addressTypeCtrl.create
//location type
case GET(p"/locationtype/all") =>
locationTypeCtrl.getAll
case GET(p"/locationtype/$id") =>
locationTypeCtrl.getById(id)
case POST(p"/locationtype/create") =>
locationTypeCtrl.create
//contact type
case GET(p"/contacttype/all") =>
contactTypeCtrl.getAll
case GET(p"/contacttype/$id") =>
contactTypeCtrl.getById(id)
case POST(p"/contacttype/create") =>
contactTypeCtrl.create
}
}
示例6: UtilRouter
//设置package包名称以及导入依赖的类
package controllers.util
import javax.inject.Inject
import play.api.routing.Router.Routes
import play.api.routing.SimpleRouter
import play.api.routing.sird._
class UtilRouter @Inject()(roleController: RoleController)(
keysController: KeysController)(
mailSettingsController: MailSettingsController,
itemsStatusCtrl: ItemsStatusCtrl)
extends SimpleRouter {
override def routes: Routes = {
//ROLES
case GET(p"/roles/all") =>
roleController.getRoles
case POST(p"/roles/create") =>
roleController.create
case GET(p"/roles/$id") =>
roleController.getRoleById(id)
//items status
case POST(p"/roles/create") =>
itemsStatusCtrl.create
case GET(p"/roles/$id") =>
itemsStatusCtrl.getById(id)
//KEYS
case GET(p"/keys/all") =>
keysController.getKeys
case POST(p"/keys/create") =>
keysController.create
case GET(p"/keys/$id") =>
keysController.getKeyById(id)
//MAIL
case GET(p"/mail/all/$siteId") =>
mailSettingsController.getSiteMailSettings(siteId)
case POST(p"/mail/create") =>
mailSettingsController.create
case GET(p"/mail/$siteId/$id") =>
mailSettingsController.getMailSettingById(siteId, id)
}
}
示例7: StorageRouter
//设置package包名称以及导入依赖的类
package controllers.storage
import javax.inject.Inject
import play.api.routing.Router.Routes
import play.api.routing.SimpleRouter
import play.api.routing.sird._
class StorageRouter @Inject()(storageUrlCtrl: StorageUrlCtrl,
fileResultsCtrl: FileResultsCtrl)
extends SimpleRouter {
override def routes: Routes = {
//storage url
case GET(p"/storageurl/all") =>
storageUrlCtrl.getAll
case GET(p"/storageurl/$id") =>
storageUrlCtrl.getById(id)
case POST(p"/storageurl/create") =>
storageUrlCtrl.create
//file result
case GET(p"/fileresult/all") =>
fileResultsCtrl.getAll
case GET(p"/fileresult/$id") =>
fileResultsCtrl.getById(id)
case POST(p"/fileresult/create") =>
fileResultsCtrl.create
}
}
示例8: 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)
}
示例9: AppApplicationLoader
//设置package包名称以及导入依赖的类
import com.softwaremill.macwire._
import controllers.Assets
import filters.StatsFilter
import play.api._
import play.api.libs.ws.ahc.AhcWSComponents
import play.api.mvc.Filter
import play.api.routing.Router.Routes
import services.{SunService, WeatherService}
import scala.concurrent.Future
class AppApplicationLoader extends ApplicationLoader {
override def load(context: ApplicationLoader.Context): Application = {
LoggerConfigurator(context.environment.classLoader).foreach { configurator =>
configurator.configure(context.environment)
}
(new BuiltInComponentsFromContext(context) with AppComponents).application
}
trait AppComponents extends BuiltInComponents with AhcWSComponents {
lazy val assets: Assets = wire[Assets]
lazy val prefix: String = "/"
lazy val router: Routes = wire[Routes]
lazy val applicationController: Application = wire[Application]
// wsClient is defined in the AhcWSComponents trait
lazy val sunService: SunService = wire[SunService]
lazy val weatherService: WeatherService = wire[WeatherService]
// Because we are using compile-time DI, we need to tell Play to include our filters in
// its chain. This can be achieved by overriding the httpFilters field from the
// BuiltInComponents trait.
// These will add a log message every time the app serves a request
lazy val statsFilter: Filter = wire[StatsFilter]
override val httpFilters: Seq[Filter] = Seq(statsFilter)
applicationLifecycle.addStopHook { () =>
Logger.info("The app is about to stop")
Future.successful(Unit)
}
val onStart = {
Logger.info("The app is about to start")
}
}
}
示例10: SystemLogRouter
//设置package包名称以及导入依赖的类
package controllers.syslog
import javax.inject.Inject
import play.api.routing.Router.Routes
import play.api.routing.SimpleRouter
import play.api.routing.sird._
class SystemLogRouter @Inject()(syslogCtrl: SystemLogEventsCtrl)
extends SimpleRouter {
override def routes: Routes = {
//System Log Events
case GET(p"/systemlog/all/$org") =>
syslogCtrl.getAll(org)
case GET(p"/systemlog/$org/$id") =>
syslogCtrl.getById(org, id)
case POST(p"/systemlog/create") =>
syslogCtrl.create
}
}
示例11: OrganisationRouter
//设置package包名称以及导入依赖的类
package controllers.organisation
import javax.inject.Inject
import play.api.routing.Router.Routes
import play.api.routing.SimpleRouter
import play.api.routing.sird._
class OrganisationRouter @Inject()(locationCtrl: LocationCtrl,
organisationCtrl: OrganisationCtrl,
organisationLogoCtrl: OrganisationLogoCtrl)
extends SimpleRouter {
override def routes: Routes = {
//location
case GET(p"/location/all/$org") =>
locationCtrl.getAll(org)
case GET(p"/location/$org/$id") =>
locationCtrl.getById(org, id)
case POST(p"/location/delete/$org/$id") =>
locationCtrl.delete(org, id)
case POST(p"/location/create") =>
locationCtrl.create
//organisation logo
case GET(p"/organisationlogo/all/$org") =>
organisationLogoCtrl.getAll(org)
case GET(p"/organisationlogo/$org/$id") =>
organisationLogoCtrl.getById(org, id)
case POST(p"/organisationlogo/create") =>
organisationLogoCtrl.create
//organisation
case GET(p"/organisation/all") =>
organisationCtrl.getAll
case GET(p"/organisation/$id") =>
organisationCtrl.getById(id)
case POST(p"/organisation/create") =>
organisationCtrl.create
}
}
示例12: BobRouter
//设置package包名称以及导入依赖的类
package v1.bob
import javax.inject.Inject
import play.api.routing.Router.Routes
import play.api.routing.SimpleRouter
import play.api.routing.sird._
class BobRouter @Inject()(
controller: BobController,
interactionController: BobInterActionController
)
extends SimpleRouter {
val prefix = "/slack/bob"
def link(id: Int): String = {
import com.netaporter.uri.dsl._
val url = prefix / id.toString
url.toString()
}
override def routes: Routes = {
case GET(p"/") => controller.index
case POST(p"/") => controller.process
case POST(p"/im") => interactionController.process
}
}
示例13: CustomRouter
//设置package包名称以及导入依赖的类
package api
import javax.inject.{Inject, Named}
import akka.actor.ActorRef
import com.viajobien.busy.actors.ProducerActor
import play.api.Logger
import play.api.libs.json.{JsNull, Json}
import play.api.mvc.Action
import play.api.mvc.Results._
import play.api.routing.Router.Routes
import play.api.routing.SimpleRouter
import repositories.RouteRepository
import services.RouteService
import scala.concurrent.{ExecutionContext, Future}
class CustomRouter @Inject()(@Named(ProducerActor.name) producerActor: ActorRef,
routeService: RouteService, routeRepository: RouteRepository
)(implicit ec: ExecutionContext) extends SimpleRouter {
override def routes: Routes = {
case _ =>
Action.async { implicit request =>
val future = this.routeService.route(
futureJson => futureJson map {
case JsNull => ServiceUnavailable(Json.obj("error" -> "Error on access service"))
case json => Ok(json)
},
() => Future.successful(BadGateway(Json.obj("error" -> "route not found")))
)
future recover {
case e =>
Logger.warn("error on getRoute", e)
ServiceUnavailable(Json.obj("error" -> "error calling route"))
}
}
}
}