Re: [akka-user] akka-http: Completing RequestContext with a Future ?

2015-03-11 Thread James Mulcahy

Hi Roland,

Thanks for the response.  You were correct - adding this makes the example 
work.  As you say, the error message could definitely be improved here :)

Cheers,

—James

> On Mar 11, 2015, at 4:58 PM, Roland Kuhn  wrote:
> 
> Hi James,
> 
> I'm on my phone right now but I think you'll need an implicit execution 
> context in scope. That error message should definitely be improved if 
> possible.
> 
> Regards,
> 
> Roland 
> 
> Sent from my iPhone
> 
> On 11 Mar 2015, at 14:24, James Mulcahy  > wrote:
> 
>> 
>> Hello,
>> 
>> I’m struggling to understand how I can complete an akka-http RequestContext 
>> asynchronously, using a future.  Synchronously completion is 
>> straightforward, e.g…...
>> 
>> val bundleRoutes = {
>>   (pathPrefix("bundles") & get) {
>> path(Segment / "meta") {
>>   bundleId => complete {
>> HttpResponse(entity = "Success!")
>>   }
>> }
>>   }
>> }
>> 
>> But I can’t find what API call I need in order to return a 
>> Future[HttpResponse].  If I do the simplest change, returning a completed 
>> future inside complete()…..
>> 
>> val bundleRoutesAsync = {
>>   (pathPrefix("bundles") & get) {
>> path(Segment / "meta") {
>>   bundleId => complete {
>> Future.successful(HttpResponse(entity = "Success!"))
>>   }
>> }
>>   }
>> }
>> 
>> …then the build fails with a type error (not necessarily too surprising).
>> 
>> type mismatch;
>> [error]  found   : scala.concurrent.Future[akka.http.model.HttpResponse]
>> [error]  required: akka.http.marshalling.ToResponseMarshallable
>> [error]   Future.successful(HttpResponse(entity = "Success!"))
>> 
>> I cannot see in the docs[1] what API I should use to achieve this.  Googling 
>> suggests that historically, with spray, using side-effecting calls with 
>> onComplete/onFailure was the right approach — but that doesn’t seem to be 
>> the case anymore. One thought was to return a Future[RouteResult] myself, 
>> but the RouteResult docs suggest that I shouldn’t be doing this.
>> 
>> I wonder if I’m missing an implicit marshaller that’ll handle the 
>> Future[HttpResponse] responses.
>> 
>> Could someone point me in the right direction here, please?
>> 
>> —James
>> 
>> [1] 
>> http://doc.akka.io/api/akka-stream-and-http-experimental/1.0-M4/?_ga=1.53285288.1092433602.1423525300#akka.http.server.RequestContext
>>  
>> 
>> 
>> -- 
>> >> 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 http://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 http://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...@google

Re: [akka-user] akka-http: Completing RequestContext with a Future ?

2015-03-11 Thread Roland Kuhn
Hi James,

I'm on my phone right now but I think you'll need an implicit execution context 
in scope. That error message should definitely be improved if possible.

Regards,

Roland 

Sent from my iPhone

> On 11 Mar 2015, at 14:24, James Mulcahy  wrote:
> 
> 
> Hello,
> 
> I’m struggling to understand how I can complete an akka-http RequestContext 
> asynchronously, using a future.  Synchronously completion is straightforward, 
> e.g…...
> 
> val bundleRoutes = {
>   (pathPrefix("bundles") & get) {
> path(Segment / "meta") {
>   bundleId => complete {
> HttpResponse(entity = "Success!")
>   }
> }
>   }
> }
> 
> But I can’t find what API call I need in order to return a 
> Future[HttpResponse].  If I do the simplest change, returning a completed 
> future inside complete()…..
> 
> val bundleRoutesAsync = {
>   (pathPrefix("bundles") & get) {
> path(Segment / "meta") {
>   bundleId => complete {
> Future.successful(HttpResponse(entity = "Success!"))
>   }
> }
>   }
> }
> 
> …then the build fails with a type error (not necessarily too surprising).
> 
> type mismatch;
> [error]  found   : scala.concurrent.Future[akka.http.model.HttpResponse]
> [error]  required: akka.http.marshalling.ToResponseMarshallable
> [error]   Future.successful(HttpResponse(entity = "Success!"))
> 
> I cannot see in the docs[1] what API I should use to achieve this.  Googling 
> suggests that historically, with spray, using side-effecting calls with 
> onComplete/onFailure was the right approach — but that doesn’t seem to be the 
> case anymore. One thought was to return a Future[RouteResult] myself, but the 
> RouteResult docs suggest that I shouldn’t be doing this.
> 
> I wonder if I’m missing an implicit marshaller that’ll handle the 
> Future[HttpResponse] responses.
> 
> Could someone point me in the right direction here, please?
> 
> —James
> 
> [1] 
> http://doc.akka.io/api/akka-stream-and-http-experimental/1.0-M4/?_ga=1.53285288.1092433602.1423525300#akka.http.server.RequestContext
> -- 
> >> 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 http://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 http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


[akka-user] akka-http: Completing RequestContext with a Future ?

2015-03-11 Thread James Mulcahy

Hello,

I’m struggling to understand how I can complete an akka-http RequestContext 
asynchronously, using a future.  Synchronously completion is straightforward, 
e.g…...

val bundleRoutes = {
  (pathPrefix("bundles") & get) {
path(Segment / "meta") {
  bundleId => complete {
HttpResponse(entity = "Success!")
  }
}
  }
}

But I can’t find what API call I need in order to return a 
Future[HttpResponse].  If I do the simplest change, returning a completed 
future inside complete()…..

val bundleRoutesAsync = {
  (pathPrefix("bundles") & get) {
path(Segment / "meta") {
  bundleId => complete {
Future.successful(HttpResponse(entity = "Success!"))
  }
}
  }
}

…then the build fails with a type error (not necessarily too surprising).

type mismatch;
[error]  found   : scala.concurrent.Future[akka.http.model.HttpResponse]
[error]  required: akka.http.marshalling.ToResponseMarshallable
[error]   Future.successful(HttpResponse(entity = "Success!"))

I cannot see in the docs[1] what API I should use to achieve this.  Googling 
suggests that historically, with spray, using side-effecting calls with 
onComplete/onFailure was the right approach — but that doesn’t seem to be the 
case anymore. One thought was to return a Future[RouteResult] myself, but the 
RouteResult docs suggest that I shouldn’t be doing this.

I wonder if I’m missing an implicit marshaller that’ll handle the 
Future[HttpResponse] responses.

Could someone point me in the right direction here, please?

—James

[1] 
http://doc.akka.io/api/akka-stream-and-http-experimental/1.0-M4/?_ga=1.53285288.1092433602.1423525300#akka.http.server.RequestContext

-- 
>>  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 http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


[akka-user] akka-http: Completing RequestContext with a Future ?

2015-03-11 Thread James Mulcahy
Hello,

I’m struggling to understand how I can complete an akka-http RequestContext 
asynchronously, using a future.  Synchronously completion is 
straightforward, e.g…...

val bundleRoutes = {
  (pathPrefix("bundles") & get) {
path(Segment / "meta") {
  bundleId => complete {
HttpResponse(entity = "Success!")
  }
}
  }
}

But I can’t find what API call I need in order to return a 
Future[HttpResponse].  If I do the simplest change, returning a completed 
future inside complete()…..

val bundleRoutesAsync = {
  (pathPrefix("bundles") & get) {
path(Segment / "meta") {
  bundleId => complete {
Future.successful(HttpResponse(entity = "Success!"))
  }
}
  }
}

…then the build fails with a type error (not necessarily too surprising).

type mismatch;
[error]  found   : scala.concurrent.Future[akka.http.model.HttpResponse]
[error]  required: akka.http.marshalling.ToResponseMarshallable
[error]   Future.successful(HttpResponse(entity = "Success!"))

I cannot see in the docs[1] what API I should use to achieve this. 
 Googling suggests that historically, with spray, using side-effecting 
calls with onComplete/onFailure was the right approach — but that doesn’t 
seem to be the case anymore. One thought was to return a 
Future[RouteResult] myself, but the RouteResult docs suggest that I 
shouldn’t be doing this.

I wonder if I’m missing an implicit marshaller that’ll handle the 
Future[HttpResponse] responses.

Could someone point me in the right direction here, please?

—James

[1] 
http://doc.akka.io/api/akka-stream-and-http-experimental/1.0-M4/?_ga=1.53285288.1092433602.1423525300#akka.http.server.RequestContext

-- 
>>  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 http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.