Just need to access routes that makes requests to the other routes, *this
doesn’t work, due to my absolute url*:

val myRoute = {
  path("/foo") {
    val url = "http://127.0.0.1:8080/bar";
    val response = Http().singleRequest(HttpRequest(uri = url))
    onComplete(response) {
      case Success(r) => complete(r)
      case Failure(_) =>
    }
  } ~
  path ("/bar") {
    complete("Hello World")
  }
}

in my test case:

Get("/foo") ~> route ~> check {...}

Sorry in my prior email I forgot to render markdown. Hope this clarifies a
bit.
​

On Tue, Apr 25, 2017 at 11:50 AM Konrad Malawski <
konrad.malaw...@lightbend.com> wrote:

> Because the route test does not actually start a real server. That's a
> feature. It allows testing all routes without involving actual parsing and
> starting servers so it is much much faster than full integration testing.
>
> If you want to bind a real server in your test simply do so same as in
> normal apps.
>
> Instead of doing requests to yourself I would recommend sharing code or
> methods inside the implementation.
>
> --
> Konrad Malawski
>
> On April 25, 2017 at 11:31:33, todd.f....@gmail.com (todd.f....@gmail.com)
> wrote:
>
>> Hi,
>>
>> I'm using akka-http to build a restful api. In one route of my app, the
>> route need to access one of my other routes in the same app, like the
>> following:
>>
>>
>>    - `/foo`, which access `/bar` and returns slightly modified content
>>    from the latter as response
>>    - `/bar`
>>
>> In the implementation of `/foo`, I used absolute path: `
>> 127.0.0.1:8080/bar`, and request by `Http().singleRequest(...)`. This
>> works fine initially, but as I start to write the test cases with akka test
>> kit(ScalatestRouteTest), the port 8080 seems cannot be accessed in my test:
>>
>> ```
>> Get("/foo") ~> route ~> check {...}
>> ```
>>
>> and it shows the error:
>>
>> ```
>> akka.stream.StreamTcpException: Tcp command 
>> [Connect(127.0.0.1:8080,None,List(),Some(10
>> seconds),true)] failed
>> ```
>>
>> Thus I'm looking for a way to make request to `/bar`, with relative URL,
>> hoping it solve this problem. Any idea is appreciated.
>>
>> ---
>> BR,
>> Todd Leo
>>
>> --
>> >>>>>>>>>> Read the docs: http://akka.io/docs/
>> >>>>>>>>>> Check the FAQ:
>> http://doc.akka.io/docs/akka/current/additional/faq.html
>> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Akka User List" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to akka-user+unsubscr...@googlegroups.com.
>> To post to this group, send email to akka-user@googlegroups.com.
>> Visit this group at https://groups.google.com/group/akka-user.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to