本文整理汇总了Scala中spray.routing.SimpleRoutingApp类的典型用法代码示例。如果您正苦于以下问题:Scala SimpleRoutingApp类的具体用法?Scala SimpleRoutingApp怎么用?Scala SimpleRoutingApp使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SimpleRoutingApp类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: Main
//设置package包名称以及导入依赖的类
package hello.scala
import akka.actor.ActorSystem
import spray.routing.SimpleRoutingApp
import scala.language.postfixOps
object Main extends App with SimpleRoutingApp {
implicit val system = ActorSystem("hello-world-system")
val interface = args(0)
val port = args(1).toInt
startServer(interface = interface, port = port) {
pathPrefix("hello-scala") {
path("hello") {
get {
complete {
s"hello-scala, world! running on $interface:$port"
}
}
} ~
path("health") {
get {
complete {
"ok!"
}
}
} ~ //this is for the loader.io verify our server
path("loaderio-93f4cb143cf6225704731e0dfc39c59a" /) {
get {
complete {
"loaderio-93f4cb143cf6225704731e0dfc39c59a"
}
}
}
}
}
}
开发者ID:gabfssilva,项目名称:hello,代码行数:42,代码来源:Main.scala
示例2: SbtServePlugin
//设置package包名称以及导入依赖的类
package com.github.michalsenkyr.sbt.serve
import akka.actor.ActorSystem
import com.typesafe.config.ConfigFactory
import sbt.Keys._
import sbt._
import spray.http.StatusCodes
import spray.routing.SimpleRoutingApp
object SbtServePlugin extends AutoPlugin with SimpleRoutingApp {
private val cl = getClass.getClassLoader
implicit val system = ActorSystem("sbt-serve", ConfigFactory.load(cl), cl)
object autoImport {
val port = settingKey[Int]("Port")
val serve = taskKey[Unit]("Serve static files")
// val packagePath = settingKey[File]("Path inside package")
}
import autoImport._
override lazy val projectSettings = Seq(
port in serve := 8000,
sourceDirectory in serve := file("src/main/web"),
serve := serveTask.value
// packagePath in serve := new File("web")
)
lazy val serveTask =
Def.task {
val srcDir = baseDirectory.value / (sourceDirectory in serve).value.getPath
if (!srcDir.exists) throw new IllegalStateException("Source directory does not exist")
startServer(interface = "localhost", port = (port in serve).value) {
pathSingleSlash {
redirect("/index.html", StatusCodes.PermanentRedirect)
} ~ get {
compressResponse() {
getFromDirectory(srcDir.getPath)
}
}
}
}
}
开发者ID:michalsenkyr,项目名称:sbt-serve,代码行数:47,代码来源:SbtServePlugin.scala
示例3: SSServer
//设置package包名称以及导入依赖的类
package com.server
import com.services.StorageService
import akka.actor.ActorSystem
import com.support.CORSSupport
import spray.http.MediaTypes
import spray.routing.{Route, SimpleRoutingApp}
object SSServer extends App with SimpleRoutingApp with CORSSupport{
implicit val actorSystem = ActorSystem()
//Custom directive to replace the inclcusion of the stated return type header
def getJson(route: Route) = get{
respondWithMediaType(MediaTypes.`application/json`){
route
}
}
//Define Each route independently as lazy vals to keep code clean
//Link the names of each route in the start server method
lazy val helloRoute = get {
cors{
path("hello") {
complete {
"Welcome to the AWS Storage Service \n here are a list of the available routes:"
}
}
}
}
lazy val store_pcs_processA = get {
cors{
path("storageServices" / "s3" / "processControllers" / "processA" / "withObject" / Segment / "andDestination" / Segment ) { (data, fileName) =>
complete {
StorageService.writeObjectToS3(data,fileName)
}
}
}
}
startServer(interface = "localhost", port = 8084) {
helloRoute~
store_pcs_processA
}
}
开发者ID:dbdev138,项目名称:DEV-FYP-AWS-Storage-Service,代码行数:55,代码来源:SSServer.scala
示例4: RestService
//设置package包名称以及导入依赖的类
package com.mentatlabs
import java.time.LocalDate
import java.util.concurrent.Executors
import akka.actor.ActorSystem
import org.slf4j.LoggerFactory
import spray.routing.SimpleRoutingApp
import scala.concurrent.ExecutionContext
object RestService extends App with SimpleRoutingApp {
val logger = LoggerFactory.getLogger(RestService.getClass)
private implicit val system = ActorSystem("docker-playground-rest")
private implicit val executionContext =
ExecutionContext.fromExecutor(Executors.newCachedThreadPool)
val routes = {
pathPrefix("ping") {
pathEnd {
get {
parameter("id") { id =>
complete {
logger.info("Handling ping request [{}]...", id)
"pong " + LocalDate.now()
}
}
}
}
} ~
pathPrefix("health") {
pathEnd {
get {
complete {
logger.debug("Handling health request...")
""
}
}
}
}
}
startServer(interface = "0.0.0.0", port = 8080) {
detach()(routes)
}
}
开发者ID:dstimac,项目名称:docker-playground,代码行数:50,代码来源:RestService.scala
示例5:
//设置package包名称以及导入依赖的类
package com.example.spray
import spray.http.HttpHeaders
import spray.routing.SimpleRoutingApp
trait Web extends SimpleRoutingApp {
this: Api with CoreActors with Core =>
val AccessControlAllowAll = HttpHeaders.RawHeader(
"Access-Control-Allow-Origin", "*"
)
val AccessControlAllowHeadersAll = HttpHeaders.RawHeader(
"Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"
)
//this is not ideal because this disables CORS checking (and is required by the Swagger UI)
startServer(interface = "0.0.0.0", port = 12345) {
respondWithHeaders(AccessControlAllowAll, AccessControlAllowHeadersAll) {
routes
}
}
}
开发者ID:pjfanning,项目名称:swagger-spray-sample,代码行数:24,代码来源:Web.scala
示例6: SprayDemo
//设置package包名称以及导入依赖的类
package spray
import akka.actor._
import spray.routing.SimpleRoutingApp
object SprayDemo extends SimpleRoutingApp {
def run(implicit system: ActorSystem) {
startServer(interface = "localhost", port = 8080) {
path("hello") {
get {
complete {
<h1>Say hello to spray</h1>
}
}
}
}
}
}
开发者ID:lustefaniak,项目名称:akka-viz-demo,代码行数:21,代码来源:SprayDemo.scala
示例7: SSServer
//设置package包名称以及导入依赖的类
package com.server
import com.services.StorageService
import akka.actor.ActorSystem
import com.support.CORSSupport
import spray.http.MediaTypes
import spray.routing.{Route, SimpleRoutingApp}
object SSServer extends App with SimpleRoutingApp with CORSSupport{
implicit val actorSystem = ActorSystem()
//Custom directive to replace the inclcusion of the stated return type header
def getJson(route: Route) = get{
respondWithMediaType(MediaTypes.`application/json`){
route
}
}
//I have defined each route independently as lazy vals to keep the code clean
//Endpoint: List avalable endpoints
lazy val helloRoute = get {
cors{
path("hello") {
complete {
"Welcome to the MicroDG AWS-Stroage-Service" +
"\n Routes:" +
"\n Store output fro, Process A: storageServices/s3/processControllers/processA/withObject/{json_object}/andDestination/{url}"
}
}
}
}
//Endpoint: Write output from Process A to an S3 bucket
lazy val store_pcs_processA = get {
cors{
path("storageServices" / "s3" / "processControllers" / "processA" / "withObject" / Segment / "andDestination" / Segment ) { (data, fileName) =>
complete {
StorageService.writeObjectToS3(data,fileName)
}
}
}
}
startServer(interface = "localhost", port = 8084) {
helloRoute~
store_pcs_processA
}
}
开发者ID:microdg,项目名称:BETA-AWS-Storage-Service,代码行数:55,代码来源:SSServer.scala
注:本文中的spray.routing.SimpleRoutingApp类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论