AKKA HTTP 简单示例
Posted tankaixiong
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了AKKA HTTP 简单示例相关的知识,希望对你有一定的参考价值。
AKKA HTTP 简单示例
依赖包:
compile("com.typesafe.akka:akka-http_2.13:10.1.8")
compile("com.typesafe.akka:akka-stream_2.13:2.5.23")
代码示例:
package http import akka.actor.ActorSystem import akka.http.javadsl.server.HttpApp import akka.http.javadsl.server.Route import akka.stream.Server import java.util.function.Supplier import akka.http.javadsl.ConnectHttp import akka.http.javadsl.Http import akka.http.javadsl.model.HttpResponse import akka.http.javadsl.model.StatusCodes import java.util.concurrent.CompletionStage import akka.stream.ActorMaterializer /** * Created by: tankx * Date: 2019/7/16 * Description: */ class HelloHttp constructor() : HttpApp() override fun routes(): Route return createRoute() private fun createRoute(): Route val path = path("hello", object : Supplier<Route> override fun get(): Route return complete("Say hello to akka-http") ) return concat(path) fun main() // boot up server using the route as defined below //val system = ActorSystem.create("routes") HelloHttp().startServer("localhost", 8888)
启动后访问地址 http://127.0.0.1:8888/hello
返回Say hello to akka-http
以上是关于AKKA HTTP 简单示例的主要内容,如果未能解决你的问题,请参考以下文章