Sorry for activating this old thread. I also had a little problem regarding 
getting good parameters. This is what I did:

Adding this code:

case class Param(name: String){
    def unapply(query: Uri.Query): Option[(String)] = {
      query.get(name)
    }
  }

  type Segment = String

  object ?{
    def unapply(uri: Uri): Option[(Uri, Uri.Query)] = {
      Option(uri -> uri.query)
    }
  }

  object &{
    def unapply(q: Uri.Query): Option[(Uri.Query, Uri.Query)] = {
      Option(q -> q)
    }
  }

  sealed trait Path

  case class SegmentPath(prev: Path, head: Segment) extends Path

  object Path{
    def unapply(uri: Uri): Option[Path] = {
      def path(p: Uri.Path): Path = {
        p.reverse
        p match {
          case Uri.Path.Empty => Root
          case Uri.Path.Segment(head, slashOrEmpty) =>
            SegmentPath(path(slashOrEmpty), head)
          case Uri.Path.Slash(tail) =>
            path(tail)
        }
      }

      if(uri.isEmpty) None else Option(path(uri.path.reverse))
    }
  }

  object Root extends Path

  object /{

    def unapply(l: Path): Option[(Path, String)] = {
      l match {
        case Root => None
        case s: SegmentPath => Option((s.prev, s.head))
      }
    }
  }

  object Id extends Param("id")


This enables me to:

val requestHandler: HttpRequest ⇒ HttpResponse = {
    case HttpRequest(GET, Path(Root / "features" / "id") ? Id(id), _, _, _) 
⇒ id
        HttpResponse(entity = HttpEntity(MediaTypes.`text/html`, 
s"<html><body>Hello world: $id!</body></html>"))
    case HttpRequest(GET, Path(Root / "features" / "are" / p / "and" / q) ? 
Id(id), _, _, _) ⇒ id
       HttpResponse(entity = HttpEntity(MediaTypes.`text/html`, 
s"<html><body>Hello world: $id! - $p and $q</body></html>"))
}

I guess the Akka developers will come up with something better, but it 
might help someone in the meanwhile. 

SK


On Wednesday, September 10, 2014 9:42:24 AM UTC+2, Karthik S wrote:
>
>
>
> Thanks Konrad,
>
> That works for 
> localhost
> ,
>  127.0.01
>
> and
> ipaddress 
>
> as well
>
>
>
>
>
>
> On Wednesday, September 10, 2014 12:20:35 PM UTC+5:30, Akka Team wrote:
>>
>> Slightly related hint: You can also Bind to 0.0.0.0, which means “any 
>> address”.
>>
>>
>> -- konrad
>> ​
>>
>> On Wed, Sep 10, 2014 at 2:01 AM, Glenn / devalias <glenn...@wlpc.com.au> 
>> wrote:
>>
>>> Hey
>>>
>>> On Tuesday, 9 September 2014 20:39:07 UTC+10, Karthik S wrote:
>>>>
>>>> Hi Endre,
>>>>
>>>> Thanks,
>>>>
>>>> I would like to know the idiomatic way of creating 
>>>> Producer[ChunkStreamPart] 
>>>> for  *HttpEntity.Chunked* Object, could you please rewrite the above 
>>>> two lines, I am not familiar with akka-streams and its api yet, that will 
>>>> be helpful for other new comers also.
>>>>
>>>> Any way thanks for your answers for my another two questions.
>>>>
>>>> The reason for last question is, this line
>>>>
>>>> *val bindingFuture = IO(Http) ? Http.Bind(interface = "localhost", port 
>>>> = 8080)*
>>>>
>>>> when I use* interface="localhost"*, I am not able to access from 
>>>> another machine in LAN, I have to change it to *interface = 
>>>> "192.168.1.111".*
>>>>
>>>>
>>> 'localhost' is a pointer to the loopback device. If you bind to it, it 
>>> means the only thing that will ever be able to communicate with it is the 
>>> local machine. Binding to 192.168.1.111 is binding to the network 
>>> addressable interface, thus other machines can see it.
>>>
>>> - Glenn / devalias
>>>  
>>>
>>>>
>>>>
>>>>
>>>> On Tuesday, September 9, 2014 3:30:01 PM UTC+5:30, drewhk wrote:
>>>>>
>>>>> Hi Karthik,
>>>>>
>>>>>
>>>>>> *def output = 
>>>>>> Source.fromFile("C:\\Users\\karthik\\Downloads\\big_buck_bunny.mp4")(scala.io.Codec.ISO8859)*
>>>>>>
>>>>>
>>>>> Using Source here will be horribly inefficient.
>>>>>  
>>>>>
>>>>>>
>>>>>>
>>>>>> *def video = HttpResponse(entity = 
>>>>>> HttpEntity.Chunked(MediaTypes.`video/mp4`, 
>>>>>> Flow(output.map(_.toByte).map(a 
>>>>>> => ChunkStreamPart(ByteString(a))*
>>>>>>
>>>>>
>>>>> The above line will try to stream the data one-by-one bytes, you 
>>>>> shouldn't use streams of Byte but stream of ByteStrings instead 
>>>>> containing 
>>>>> larger chunks (probably a few kilobytes).
>>>>>  
>>>>>
>>>>>> *)).toProducer(materializer)))*
>>>>>>
>>>>>>
>>>>>> I would also like to know, how to pass parameters with urls(some 
>>>>>> thing like* "/video/:id*"  not as */video?id=1"*).
>>>>>>
>>>>>
>>>>> The routing DSL is still in progress, so this part is not implemented 
>>>>> yet.
>>>>>  
>>>>>
>>>>>>
>>>>>> and what is the internal http-server used by akk-http?(like spray-can 
>>>>>> or jetty ?)
>>>>>>
>>>>>
>>>>> It is a standalone module, it does not use Spray (since it is spray 
>>>>> code ported to Akka) or Jetty, only Akka IO
>>>>>
>>>>> -Endre
>>>>>  
>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> Thank you.
>>>>>>
>>>>>> -- 
>>>>>> >>>>>>>>>> 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+...@googlegroups.com.
>>>>>> To post to this group, send email to akka...@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+...@googlegroups.com.
>>> To post to this group, send email to akka...@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/akka-user.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> -- 
>> Akka Team
>> Typesafe - The software stack for applications that scale
>> Blog: letitcrash.com
>> Twitter: @akkateam
>>  
>

-- 
>>>>>>>>>>      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.

Reply via email to