akka-http

How to test client-side Akka HTTP

别等时光非礼了梦想. 提交于 2021-02-17 21:33:35
问题 I've just started testing out the Akka HTTP Request-Level Client-Side API (Future-Based). One thing I've been struggling to figure out is how to write a unit test for this. Is there a way to mock the response and have the future completed without having to actually do an HTTP request? I was looking at the API and the testkit package, trying to see how I could use that, only to find in the docs that it actually says: akka-http-testkit A test harness and set of utilities for verifying server

How to test client-side Akka HTTP

霸气de小男生 提交于 2021-02-17 21:32:13
问题 I've just started testing out the Akka HTTP Request-Level Client-Side API (Future-Based). One thing I've been struggling to figure out is how to write a unit test for this. Is there a way to mock the response and have the future completed without having to actually do an HTTP request? I was looking at the API and the testkit package, trying to see how I could use that, only to find in the docs that it actually says: akka-http-testkit A test harness and set of utilities for verifying server

Treat index.html as default file in Akka HTTP's getFromDirectory

元气小坏坏 提交于 2021-02-09 06:59:29
问题 Assuming I have a folder foo with an index.html file in it and the following minimal (but most likely not functional) server code for Akka HTTP below: object Server extends App { val route: Route = pathPrefix("foo") { getFromDirectory("foo") } Http().bindAndHandle(route, "0.0.0.0", 8080) } index.html will correctly be served if I open http://localhost:8080/foo/index.html in a browser, but not if I open http://localhost:8080/foo or http://localhost:8080/foo/ . If this is even possible, how can

Treat index.html as default file in Akka HTTP's getFromDirectory

谁说我不能喝 提交于 2021-02-09 06:58:48
问题 Assuming I have a folder foo with an index.html file in it and the following minimal (but most likely not functional) server code for Akka HTTP below: object Server extends App { val route: Route = pathPrefix("foo") { getFromDirectory("foo") } Http().bindAndHandle(route, "0.0.0.0", 8080) } index.html will correctly be served if I open http://localhost:8080/foo/index.html in a browser, but not if I open http://localhost:8080/foo or http://localhost:8080/foo/ . If this is even possible, how can

how to resolve conflict of ActorSystem in akka http test and akka test kit

▼魔方 西西 提交于 2020-12-26 11:11:17
问题 i have a test class in which i need to use both akka testkit and akka http test kit so i am doing it like this class MyTest extends TestKit(ActorSystem("testsys")) with ScalaFutures with ImplicitSender with AnyWordSpecLike with Matchers with BeforeAndAfterAll with ScalatestRouteTest { //tests here } but i am getting a compile time error implicit val system: akka.actor.ActorSystem (defined in class TestKit) and [error] implicit val system: akka.actor.ActorSystem (defined in trait RouteTest)

how to resolve conflict of ActorSystem in akka http test and akka test kit

雨燕双飞 提交于 2020-12-26 11:08:14
问题 i have a test class in which i need to use both akka testkit and akka http test kit so i am doing it like this class MyTest extends TestKit(ActorSystem("testsys")) with ScalaFutures with ImplicitSender with AnyWordSpecLike with Matchers with BeforeAndAfterAll with ScalatestRouteTest { //tests here } but i am getting a compile time error implicit val system: akka.actor.ActorSystem (defined in class TestKit) and [error] implicit val system: akka.actor.ActorSystem (defined in trait RouteTest)

Spray-Json: serialize None as null

夙愿已清 提交于 2020-12-12 10:13:46
问题 I am porting a rest API to scala, using akka-http with spray-json. The old API had the following response: { "result": { ... }, "error": null } Now I want to maintain exact backwards compatibility, so when there's no error I want an error key with a null value. However I can't see any support for this in spray-json. When I serialize the following with a None error: case class Response(result: Result, error: Option[Error]) I end up with { "result": { ... } } And it completely drops the error

Akka-http - configuration of request and host-level pools

China☆狼群 提交于 2020-06-13 06:12:34
问题 What is the relationship in terms of pool settings between the super-pool used by the Request-level API, and the cached pool created by the host-level API? To provide more context: I need to query the same host/endpoint with fast, responsive requests, and with more expensive requests. My current strategy is to use Http().singleRequest() for the cheap queries, and a cached host-pool to "isolate" the more expensive queries. I want to make sure that the expensive queries won't use up all the

Akka-http - configuration of request and host-level pools

不羁岁月 提交于 2020-06-13 06:11:09
问题 What is the relationship in terms of pool settings between the super-pool used by the Request-level API, and the cached pool created by the host-level API? To provide more context: I need to query the same host/endpoint with fast, responsive requests, and with more expensive requests. My current strategy is to use Http().singleRequest() for the cheap queries, and a cached host-pool to "isolate" the more expensive queries. I want to make sure that the expensive queries won't use up all the

AkkaHTTP: Getting content out of an HttpEntity

放肆的年华 提交于 2020-01-22 03:29:06
问题 I'm working with AkkaHTTP in Scala, trying to interact with an API, but I'm having some trouble getting data with certain API calls. Basically, I have a curl command which works in my terminal for any valid API call to this certain API, but in my current code I only get the actual data for calls whose responses are small enough. My first attempt was using sys.process._ and the !! method on a string with "curl (url) -X GET -H \"Authorization: Bearer (auth token)\" (which is the command that