- 浏览: 2502034 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
Spray(7)REST API Project - Routing
5. How to deal with routing
First start class Boot.scala
package com.sillycat.easysprayrestserver
import spray.can.server.SprayCanHttpServerApp
import akka.actor.Props
import com.sillycat.easysprayrestserver.bootstrap.Bootstrap
import com.sillycat.easysprayrestserver.actor.URLRouterActor
object Boot extends App with Bootstrap with SprayCanHttpServerApp {
valhandler = system.actorOf(Props[URLRouterActor])
newHttpServer(handler) ! Bind(interface = serverAddress, port = serverPort)
}
Bootstrap.scala to prepare some parameters
package com.sillycat.easysprayrestserver.bootstrap
import akka.actor.ActorSystem
import com.typesafe.config.ConfigFactory
trait Bootstrap {
//implicit val system = ActorSystem("RESTAPIService")
valconfig = ConfigFactory.load()
valenv = config.getString("build.env")
varserverAddress: String = config.getString("server.address")
varserverPort: Int = config.getInt("server.port")
if (env != null && env != "") {
serverAddress = if (config.getString("environment." + env + ".server.address") != null) config.getString("environment." + env + ".server.address") elseserverAddress
serverPort = if (config.getInt("environment." + env + ".server.port") != 0) config.getInt("environment." + env + ".server.port") elseserverPort
}
}
URLRouterActor to manage the URL resources
package com.sillycat.easysprayrestserver.actor
import akka.actor.{ Props, Actor }
import spray.routing._
import spray.routing.directives._
import spray.util.LoggingContext
import spray.http.StatusCodes._
import spray.httpx.SprayJsonSupport._
import shapeless._
class URLRouterActor extends Actor with URLRouterService {
def actorRefFactory = context
def receive = runRoute(route)
}
trait URLRouterService extends HttpService {
def route = {
pathPrefix(Version / BrandCode) { (apiVersion, brandCode) =>
path("resource" / "all") {
get {
complete {
"Morning, guest. apiVersion = " + apiVersion + ", brandCode =" + brandCode
}
}
} ~
path("resource" / "admin-only") {
get {
complete {
"Morning, admin-only. apiVersion = " + apiVersion + ", brandCode =" + brandCode
}
}
} ~
path("resource" / "customer-only") {
get {
complete {
"Morning, customer-only. apiVersion = " + apiVersion + ", brandCode =" + brandCode
}
}
} ~
path("resource" / "better-admin") {
get {
complete {
"Morning, better-admin. apiVersion = " + apiVersion + ", brandCode =" + brandCode
}
}
} ~
path("resource" / "better-customer") {
get {
complete {
"Morning, better-customer. apiVersion = " + apiVersion + ", brandCode =" + brandCode
}
}
}
}
}
valVersion = PathMatcher("""v([0-9]+)""".r)
.flatMap {
casestring :: HNil => {
try Some(java.lang.Integer.parseInt(string) :: HNil)
catch {
case _: NumberFormatException => None
}
}
}
valBrandCode = PathElement
}
Visit the URL as follow to verify that.
http://localhost:9000/v1/sillycat/resource/better-customer
6. How to Deal with Auth
7. How to work with DB
come soon...
8. How to Work with Actor
come soon…
9. How to do Validation
come soon...
10. How to Work with Logback
come soon…
Tips:
1. Add formatter to plugins
project/plugins.sbt
addSbtPlugin("com.typesafe.sbt" % "sbt-scalariform" % "1.0.1")
References:
http://www.gtan.com/akka_doc/scala/routing.html
https://github.com/cakesolutions/spray-auth-example
http://spray.io/documentation/spray-routing/
https://github.com/spray/spray/wiki/Authentication-Authorization
https://github.com/spray/spray/wiki/Configuration
https://github.com/spray/spray/wiki
5. How to deal with routing
First start class Boot.scala
package com.sillycat.easysprayrestserver
import spray.can.server.SprayCanHttpServerApp
import akka.actor.Props
import com.sillycat.easysprayrestserver.bootstrap.Bootstrap
import com.sillycat.easysprayrestserver.actor.URLRouterActor
object Boot extends App with Bootstrap with SprayCanHttpServerApp {
valhandler = system.actorOf(Props[URLRouterActor])
newHttpServer(handler) ! Bind(interface = serverAddress, port = serverPort)
}
Bootstrap.scala to prepare some parameters
package com.sillycat.easysprayrestserver.bootstrap
import akka.actor.ActorSystem
import com.typesafe.config.ConfigFactory
trait Bootstrap {
//implicit val system = ActorSystem("RESTAPIService")
valconfig = ConfigFactory.load()
valenv = config.getString("build.env")
varserverAddress: String = config.getString("server.address")
varserverPort: Int = config.getInt("server.port")
if (env != null && env != "") {
serverAddress = if (config.getString("environment." + env + ".server.address") != null) config.getString("environment." + env + ".server.address") elseserverAddress
serverPort = if (config.getInt("environment." + env + ".server.port") != 0) config.getInt("environment." + env + ".server.port") elseserverPort
}
}
URLRouterActor to manage the URL resources
package com.sillycat.easysprayrestserver.actor
import akka.actor.{ Props, Actor }
import spray.routing._
import spray.routing.directives._
import spray.util.LoggingContext
import spray.http.StatusCodes._
import spray.httpx.SprayJsonSupport._
import shapeless._
class URLRouterActor extends Actor with URLRouterService {
def actorRefFactory = context
def receive = runRoute(route)
}
trait URLRouterService extends HttpService {
def route = {
pathPrefix(Version / BrandCode) { (apiVersion, brandCode) =>
path("resource" / "all") {
get {
complete {
"Morning, guest. apiVersion = " + apiVersion + ", brandCode =" + brandCode
}
}
} ~
path("resource" / "admin-only") {
get {
complete {
"Morning, admin-only. apiVersion = " + apiVersion + ", brandCode =" + brandCode
}
}
} ~
path("resource" / "customer-only") {
get {
complete {
"Morning, customer-only. apiVersion = " + apiVersion + ", brandCode =" + brandCode
}
}
} ~
path("resource" / "better-admin") {
get {
complete {
"Morning, better-admin. apiVersion = " + apiVersion + ", brandCode =" + brandCode
}
}
} ~
path("resource" / "better-customer") {
get {
complete {
"Morning, better-customer. apiVersion = " + apiVersion + ", brandCode =" + brandCode
}
}
}
}
}
valVersion = PathMatcher("""v([0-9]+)""".r)
.flatMap {
casestring :: HNil => {
try Some(java.lang.Integer.parseInt(string) :: HNil)
catch {
case _: NumberFormatException => None
}
}
}
valBrandCode = PathElement
}
Visit the URL as follow to verify that.
http://localhost:9000/v1/sillycat/resource/better-customer
6. How to Deal with Auth
7. How to work with DB
come soon...
8. How to Work with Actor
come soon…
9. How to do Validation
come soon...
10. How to Work with Logback
come soon…
Tips:
1. Add formatter to plugins
project/plugins.sbt
addSbtPlugin("com.typesafe.sbt" % "sbt-scalariform" % "1.0.1")
References:
http://www.gtan.com/akka_doc/scala/routing.html
https://github.com/cakesolutions/spray-auth-example
http://spray.io/documentation/spray-routing/
https://github.com/spray/spray/wiki/Authentication-Authorization
https://github.com/spray/spray/wiki/Configuration
https://github.com/spray/spray/wiki
发表评论
-
NodeJS12 and Zlib
2020-04-01 07:44 446NodeJS12 and Zlib It works as ... -
Traefik 2020(1)Introduction and Installation
2020-03-29 13:52 303Traefik 2020(1)Introduction and ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 390Private Registry 2020(1)No auth ... -
Buffer in NodeJS 12 and NodeJS 8
2020-02-25 06:43 351Buffer in NodeJS 12 and NodeJS ... -
NodeJS ENV Similar to JENV and PyENV
2020-02-25 05:14 435NodeJS ENV Similar to JENV and ... -
Prometheus HA 2020(3)AlertManager Cluster
2020-02-24 01:47 382Prometheus HA 2020(3)AlertManag ... -
Serverless with NodeJS and TencentCloud 2020(5)CRON and Settings
2020-02-24 01:46 310Serverless with NodeJS and Tenc ... -
GraphQL 2019(3)Connect to MySQL
2020-02-24 01:48 222GraphQL 2019(3)Connect to MySQL ... -
GraphQL 2019(2)GraphQL and Deploy to Tencent Cloud
2020-02-24 01:48 409GraphQL 2019(2)GraphQL and Depl ... -
GraphQL 2019(1)Apollo Basic
2020-02-19 01:36 288GraphQL 2019(1)Apollo Basic Cl ... -
Serverless with NodeJS and TencentCloud 2020(4)Multiple Handlers and Running wit
2020-02-19 01:19 283Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(3)Build Tree and Traverse Tree
2020-02-19 01:19 279Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(2)Trigger SCF in SCF
2020-02-19 01:18 263Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(1)Running with Component
2020-02-19 01:17 252Serverless with NodeJS and Tenc ... -
NodeJS MySQL Library and npmjs
2020-02-07 06:21 251NodeJS MySQL Library and npmjs ... -
Python Library 2019(1)requests and aiohttp
2019-12-18 01:12 238Python Library 2019(1)requests ... -
NodeJS Installation 2019
2019-10-20 02:57 535NodeJS Installation 2019 Insta ... -
Monitor Tool 2019(2)Monit on Multiple Instances and Email Alerts
2019-10-18 10:57 238Monitor Tool 2019(2)Monit on Mu ... -
Sqlite Database 2019(1)Sqlite3 Installation and Docker phpsqliteadmin
2019-09-05 11:24 334Sqlite Database 2019(1)Sqlite3 ... -
Supervisor 2019(2)Ubuntu and Multiple Services
2019-08-19 10:53 335Supervisor 2019(2)Ubuntu and Mu ...
相关推荐
AndroidAsync.zip,用于Android的异步套接字、HTTP(客户端 服务器)、WebSocket和socket.io库。基于nio,而不是threads.asynchronous socket、http(client server)和android的websocket库。基于nio,而不是线程。
spray-actor-per-request, 使用每个请求模型中的参与者的示例 Spray 应用程序 每个请求的 Spray这个项目提供了一个示例 Spray 应用程序,它使用每个请求模型中的参与者。为什么要为每个HTTP请求启动一个参与者?轻松...
官方版本,亲测可用
官方版本,亲测可用
官方版本,亲测可用
官方版本,亲测可用
$ git clone git://github.com/spray/spray-template.git my-project 将目录更改为您的克隆: $ cd 我的项目 启动 SBT: $ sbt 编译一切并运行所有测试: 测试 启动应用程序: 重新开始 浏览到以查看 angular...
官方版本,亲测可用
官方版本,亲测可用
官方版本,亲测可用
官方版本,亲测可用
Spray-assisted assembled spherical boron nitride as fillers
dropwizard-testing-integration.zip,使用DropWizard运行完整堆栈集成测试的实用程序和设置。用于编写DropWizard集成测试的实用程序。
概要该项目解释了如何使用具有 CORS 支持的 Spray 实现 REST API假设我假设你有经验和你的工作环境准备好使用以下技术/框架: Akka、SBT、CORS、Spray、cURL、Scala、Git要求这篇文章面向那些有 Scala 工作经验并...
$ git clone https://github.com/Gneotux/pfc-spray.git my-project 将目录更改为您的克隆: $ cd my-project 3(可选)。 使用{DIRECTORY} /src/main/resources/schema.sql中的脚本在postgres中创建数据库,修改...
喷雾Swagger模板 ... $ git clone git://github.com/zouzias/spray-swagger-template my-project 将目录更改为您的克隆: $ cd my-project 启动SBT: $ sbt run 浏览到 使用CTRL-C停止应用程序 在了解更多信息