How to extract all form fields at once?

505 views
Skip to first unread message

Fedor Tokarev

unread,
Nov 26, 2012, 12:23:50 PM11/26/12
to spray...@googlegroups.com
Hello,

I've found this page https://github.com/spray/spray/wiki/Form-Field-Filters, where it is noted that I can do this:

content(as[FormData]){ formData =>

}

But that wiki is about 0.9.0 -- a lot of things has happened since then. What is a current way to extract all form fields at once?

Fedor Tokarev

unread,
Nov 27, 2012, 12:04:31 AM11/27/12
to spray...@googlegroups.com
Solution:

  def allFormFields: Directive[Map[String,String] :: HNil] = {
    extract(_.request.entity.as[FormData].right.map(_.fields)).flatMap{
      case Right(value) => provide(value)
      case Left(_) => reject
    }
  }

понедельник, 26 ноября 2012 г., 21:23:51 UTC+4 пользователь Fedor Tokarev написал:

Mathias

unread,
Nov 27, 2012, 3:27:22 AM11/27/12
to spray...@googlegroups.com
Fedor,

actually you might want to use the `entity` directive as such:

entity(as[FormData]) { formData =>
...
}

Still, your implementation suggestion is pretty close to how the `entity` directive is implemented:
https://github.com/spray/spray/blob/master/spray-routing/src/main/scala/spray/routing/directives/MarshallingDirectives.scala#L36

Cheers,
Mathias

---
mat...@spray.io
http://spray.io
> --
>
>

Reply all
Reply to author
Forward
0 new messages