1.scala开发环境介绍

2.scala插件的demo模板介绍

3.akka-http提供demo研究

4.添加路由机制解析

package org.netsharp.rest

import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model.{ContentTypes, HttpEntity}
import akka.http.scaladsl.server.Directives._
import akka.stream.ActorMaterializer import scala.io.StdIn object WebServer { def main(args:Array[String]):Unit={ implicit val system = ActorSystem("netsharp")
implicit val materializer = ActorMaterializer()
implicit val executionContext = system.dispatcher val userRoute = path("user"){
get{
complete(HttpEntity(ContentTypes.`text/html(UTF-8)`, "<h1>Say user to akka-http</h1>"))
}
} val orderRoute = path("order"){
get{
complete(HttpEntity(ContentTypes.`text/html(UTF-8)`, "<h1>Say order to akka-http</h1>"))
}
} val customerRoute = path("customer"){
get{
complete(HttpEntity(ContentTypes.`text/html(UTF-8)`, "<h1>Say customer to akka-http</h1>"))
}
} val routes =
pathPrefix("v1") {
userRoute ~ orderRoute ~ customerRoute
} ~ path("")(getFromResource("public/index.html")) val bindingFuture = Http().bindAndHandle(routes,"localhost",80) println(s"Server online at http://localhost:80/\nPress RETURN to stop...") StdIn.readLine() bindingFuture.flatMap(_.unbind())
.onComplete(_=>system.terminate())
}
}

4.通过变量解析路径

package org.netsharp.rest

import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model.{ContentTypes, HttpEntity}
import akka.http.scaladsl.server.Directives._
import akka.stream.ActorMaterializer import scala.io.StdIn object WebServer { def main(args:Array[String]):Unit={ implicit val system = ActorSystem("netsharp")
implicit val materializer = ActorMaterializer()
implicit val executionContext = system.dispatcher val xroute=path(Segment/Segment/Segment){(v,domain,operation)=>
get{
complete(HttpEntity(ContentTypes.`text/html(UTF-8)`, s"version:$v;domain:$domain;operation:$operation"))
}
} val bindingFuture = Http().bindAndHandle(xroute,"localhost",80) println(s"Server online at http://localhost:80/\nPress RETURN to stop...") StdIn.readLine() bindingFuture.flatMap(_.unbind())
.onComplete(_=>system.terminate())
}
}

a.sbt启动项目:run

b.浏览器中输入地址:http://localhost/v1/user/create

c.显示为:version:v1;domain:user;operation:create

5.路由机制的多级变量

package org.netsharp.rest

import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model.{ContentTypes, HttpEntity}
import akka.http.scaladsl.server.Directives._
import akka.stream.ActorMaterializer import scala.io.StdIn object WebServer { def main(args:Array[String]):Unit={ implicit val system = ActorSystem("netsharp")
implicit val materializer = ActorMaterializer()
implicit val executionContext = system.dispatcher val xroute=path(Segments){xs=>
get{
complete(HttpEntity(ContentTypes.`text/html(UTF-8)`, xs.toString()))
}
} val bindingFuture = Http().bindAndHandle(xroute,"localhost",80) println(s"Server online at http://localhost:80/\nPress RETURN to stop...") StdIn.readLine() bindingFuture.flatMap(_.unbind())
.onComplete(_=>system.terminate())
}
}

a.sbt启动项目:run

b.浏览器中输入地址:http://localhost/v1/user/create

c.显示为:List(v1, user, create)

6.akka-http与actor结合

基于akka-http搭建restfull框架的更多相关文章

  1. 基于maven从头搭建springMVC框架

    0.准备工作 首先将eclipse和需要的插件准备好,例如maven插件,spring IDE插件. 1.建立maven下的webapp项目 1.新建一个maven项目,类型为webapp,如下图 2 ...

  2. 基于Docker的TensorFlow机器学习框架搭建和实例源码解读

    概述:基于Docker的TensorFlow机器学习框架搭建和实例源码解读,TensorFlow作为最火热的机器学习框架之一,Docker是的容器,可以很好的结合起来,为机器学习或者科研人员提供便捷的 ...

  3. Java之基于Eclipse搭建SSH框架(下)

    在上篇博客里,我简介了Tomcat滴配置与Struts2滴搭建,假设对这个还不会滴童鞋去看一下我滴上篇博客<Java之基于Eclipse搭建SSH框架(上)>.今天我们接着上篇博客滴内容. ...

  4. 搭建web框架手册(一)

    昨天听完永康对EASYUI的介绍后终于明白了优秀的UI框架就是第一生产力,过去自己一直沉浸在后端代码中,完全忽视了前端的生产力交互,总觉得界面漂亮就是生产力,其实大错特错,真正的具有高效生产力的界面其 ...

  5. 脚手架快速搭建springMVC框架项目

    apid-framework脚手架快速搭建springMVC框架项目   rapid-framework介绍:   一个类似ruby on rails的java web快速开发脚手架,本着不重复发明轮 ...

  6. 手工搭建ABP框架(1) - Web项目

    为了防止不提供原网址的转载,特在这里加上原文链接: http://www.cnblogs.com/skabyy/p/7295533.html ABP是 ASP.NET Boilerplate Proj ...

  7. IDEA搭建SSMM框架(详细过程)

    IDEA搭建SSMM框架(详细过程) 相关环境 Intellij IDEA Ultimate Tomcat JDK MySql 5.6(win32/win64) Maven (可使用Intellij ...

  8. Eclipse中使用Maven搭建SSM框架

    Eclipse中不使用Maven搭建SSM框架:https://www.cnblogs.com/xuyiqing/p/9569459.html IDEA中使用Maven搭建SSM框架:https:// ...

  9. 第n次搭建 SSM 框架

    什么说第 N 次搭建SSM框架呢? 刚学习java的时候,搭建 SSM 框架想做一个个人项目之类的,后来没搭起来,也就拖延了,进入公司之后,接触的第一个项目就是SSM的,模仿了一下,也能搭个简简单单的 ...

随机推荐

  1. SqlDbx 个人版本使用指定的instant client

    set Oracle_Home=D:\Toolkit\Oracle kits\instantclient_x86 set TNS_ADMIN=%Oracle_Home% set NLS_LANG=SI ...

  2. 轻量应用服务器 访问jsp页面就直接下载的问题

    本地localhost 运行可以 用自己的ip不行.出现这个问题实质原因就是Tomcat服务器就没有起到作用,运行不了jsp文件.这个是核心.去排查错误!网上查了好几天了根本没有解决我的我的问题. 1 ...

  3. SpringSecurity-ExceptionTranslationFilter的作用

    ExceptionTranslationFilter捕获异常并做相应的处理.处理逻辑如下: 1.首先判断是不是SpringSecurity产生的异常,如果是将在handleSpringSecurity ...

  4. 服务器tcp连接timewait过多优化及详细分析

    [背景说明] 在7层负载均衡上,查询网络状态发现timewait太多,于是开始准备优化事宜 整体的拓扑结构,前面是lvs做dr模式的4层负载均衡,后端使用(nginx.or haproxy)做7层负载 ...

  5. SAS LOGISTIC 逻辑回归中加(EVENT='1')和不加(EVENT='1')区别

    区别在于:最大似然估计分析中估计是刚好正负对调加上EVENT:%LET DVVAR = Y;%LET LOGIT_IN = S.T3;%LET LOGIT_MODEL = S.Model_Params ...

  6. [持续交付实践] pipeline使用:快速入门

    什么是pipeline 先介绍下什么是Jenkins 2.0,Jenkins 2.0的精髓是Pipeline as Code,是帮助Jenkins实现CI到CD转变的重要角色.什么是Pipeline, ...

  7. libevent安装后缺少libevent_openssl.so

    最近要使用阿里的rocketmq,需要依赖libevent,所以下了个源码自己编译安装,安装过程按照readme来的: 1 ./configure 2 make 3 make install 但是安装 ...

  8. python学习笔记_week28

    heap import heapq import random heap = [] data = list(range(10000)) random.shuffle(data) # for num i ...

  9. leetcode136

    public class Solution { public int SingleNumber(int[] nums) { Dictionary<int, int> dic = new D ...

  10. leetcode739

    class Solution(object): def dailyTemperatures(self, T: 'List[int]') -> 'List[int]': S = list() n ...