Hi Alexey,

I wonder if you have found a solution. You can complete requests with
anything as long as there is a marshaller for that. As you have noticed
akka-http is build on top of akka-stream so writing a marshaller for a
Source is quite trivial:

val flow = Flow.empty[(Int, String)].map { case (param, cookie) =>
s"Param: $param and cookie $cookie" }  implicit def
stringStreamMarshaller(implicit ec: ExecutionContext):
ToResponseMarshaller[Source[String]] =
  Marshaller.withFixedCharset(MediaTypes.`text/plain`,
HttpCharsets.`UTF-8`) { s =>
    HttpResponse(entity =
HttpEntity.CloseDelimited(MediaTypes.`text/plain`,
s.map(ByteString(_))))
  }

val routes = {
  path("test") {
    get {
      complete {
        Source.single(123, "crunchy").via(flow)
      }
    }
  }}

You can find runable example here:
https://github.com/2m/akka-stream-sandbox/blob/b5d77fd025a0997d6943886bdf92b2ac6063d107/src/main/scala/HttpFlow.scala


On Tue, Feb 10, 2015 at 6:48 PM, Alexey Romanchuk <
[email protected]> wrote:

> Hi!
>
> My first implementation was almost the same - one flow instantiation for
> one request. Right now I have one long living flow and push elements into
> it and then send them back to akka-http. What I want to achieve is to wire
> my flow with flow processing inside akka-http
>
> вторник, 10 февраля 2015 г., 9:39:15 UTC+6 пользователь Steve Myers
> написал:
>
>> Hi, have you seen the recent akka-http-microservice
>> <https://github.com/theiterators/akka-http-microservice> example?  It
>> may not be exactly what you want but does a great job showing how to do
>> akka-http routing.
>>
>> On Monday, February 9, 2015 at 7:21:52 PM UTC-8, Alexey Romanchuk wrote:
>>>
>>> Hello!
>>>
>>> As I understand from docs akka-http seamless integrates with akka-stream
>>> by passing flow to handleWith method. Also we have well known routing dsl
>>> from spray with all these nested directives. But I can not figure out how
>>> to use them together.
>>>
>>> I want to have routing dsl together with seamless akka streams
>>> integration. Something like this:
>>>
>>> val flow1 = Flow[(Int, String), X] //X can be marshalled
>>>
>>> respondWithHeaders(...) {
>>> path("...") {
>>> get {
>>>                     parameters("...".as[Int]?) { param =>
>>>      optionalCookie("...") { cookie =>
>>>      (param, cookie) -> flow1
>>>      }
>>>         }
>>> }
>>> } ~
>>> ...
>>> }
>>>
>>> Dsl is very useful to extract parameters and matches and flows is very
>>> natural way to build responses. This is not concrete API, but an idea how
>>> it may looks like. Any thoughts?
>>>
>>> Thanks!
>>>
>>> p.s. If I miss something obvious form docs please point me to it :)
>>>
>>  --
> >>>>>>>>>> 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 [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Martynas Mickevičius
Typesafe <http://typesafe.com/> – Reactive
<http://www.reactivemanifesto.org/> Apps on the JVM

-- 
>>>>>>>>>>      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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to