Extract HTTP Query Params - `parameters` v. `anyParams`

13 views
Skip to the first unread message

Kevin Meredith

unread,
30 Jun 2015, 14:37:2230/06/2015
to spray...@googlegroups.com
I saw this post on extraction of HTTP query parameters:  http://stackoverflow.com/a/20015748/409976.

Is this approach idiomatic for spray 1.3? 

In addition, I saw anyParams. Is one approach preferred to the other? Why?

LN

unread,
30 Jun 2015, 14:51:4130/06/2015
to spray...@googlegroups.com
I don't think you ever want to reach for 

entity(as[HttpRequest])

The predefined directives exist to help you out here. 

Here's how I use them in my code:

parameters('link_id.as[Long], 'story_id.as[Long] ?, 'thumbnail ?, 'title.?, 'description.?, 'hidden.as[Boolean] ?) { (linkId, storyId, thumbnail, title, description, hidden) =>


Without any additional constraints, parameter('foo) is extracted as a String. You can also us .as[Foo] so long as Foo is something that can be extracted. There are built-in extractions for common things. The `?` makes the param an Option(al) value. That's what I consider to be idiomatic. Always reach for the higher-level tools before dropping down to the raw HttpRequest object.
Reply all
Reply to author
Forward
0 new messages