• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala Routes类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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)
       
      
  }
} 
开发者ID:heinrich10,项目名称:scala-mvc-sample,代码行数:32,代码来源:UserRouter.scala


示例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
  }
} 
开发者ID:boniface,项目名称:hworkapi,代码行数:20,代码来源:OrganisationRouter.scala


示例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
  }
} 
开发者ID:boniface,项目名称:hworkapi,代码行数:20,代码来源:UtilRouter.scala


示例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)
  }

} 
开发者ID:TrungSpy,项目名称:scala-api-lib,代码行数:32,代码来源:PostRouter.scala


示例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

  }
} 
开发者ID:boniface,项目名称:infoshareapi,代码行数:40,代码来源:LocationRouter.scala


示例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)

  }
} 
开发者ID:boniface,项目名称:infoshareapi,代码行数:48,代码来源:UtilRouter.scala


示例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

  }
} 
开发者ID:boniface,项目名称:infoshareapi,代码行数:31,代码来源:StorageRouter.scala


示例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)
} 
开发者ID:xuwei-k,项目名称:httpmock,代码行数:52,代码来源:Setting.scala


示例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")
        }
    }
} 
开发者ID:Ryan-Thomas,项目名称:WebDevScala,代码行数:46,代码来源:AppApplicationLoader.scala


示例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
  }
} 
开发者ID:boniface,项目名称:infoshareapi,代码行数:21,代码来源:SystemLogRouter.scala


示例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
  }
} 
开发者ID:boniface,项目名称:infoshareapi,代码行数:41,代码来源:OrganisationRouter.scala


示例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
  }
} 
开发者ID:ridi-data,项目名称:Bob,代码行数:28,代码来源:BobRouter.scala


示例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"))
        }
      }
  }

} 
开发者ID:viajobien,项目名称:busy-example,代码行数:43,代码来源:CustomRouter.scala



注:本文中的play.api.routing.Router.Routes类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala StatusCodes类代码示例发布时间:2022-05-23
下一篇:
Scala text类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap