The best way to route end

31 views
Skip to first unread message

Stas Shevchenko

unread,
Feb 25, 2015, 12:16:12 PM2/25/15
to spray...@googlegroups.com
Hi,

I have HttpService that support operations

/api/operation1/{some_suffix_needs_to_map_to_val}
/api/operation2/{some_suffix_needs_to_map_to_val}
/api/operation3/{some_suffix_needs_to_map_to_val}
/api/operation4/{some_suffix_needs_to_map_to_val}

what is the best way to handle it via spray routing?

Stas

Jim Hazen

unread,
Feb 26, 2015, 2:46:01 AM2/26/15
to spray...@googlegroups.com
http://spray.io/documentation/1.2.2/spray-routing/path-directives/pathmatcher-dsl/#pathmatcher-dsl

Probably something like

path(/ "api" / "operation1" / Segment) {somestring => ...}

or

path(/ "api" / "operation1" / RestPath) {somestring => ...}

depending on the nature of the URI after the operation.

Mathias Doenitz

unread,
Feb 26, 2015, 3:05:23 AM2/26/15
to spray...@googlegroups.com
Stas,

building on Jim’s comment:
The PathMatcher DSL directly supports maps, so you can do something like

val suffixMap = Map(“foo” -> 42, “bar” -> 11)

val route =
path(“api” / “operation” / suffixMap) { i =>

}

Cheers,
Mathias

---
mat...@spray.io
http://spray.io
> --
> You received this message because you are subscribed to the Google Groups "spray.io User List" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to spray-user+...@googlegroups.com.
> Visit this group at http://groups.google.com/group/spray-user.
> To view this discussion on the web visit https://groups.google.com/d/msgid/spray-user/baac464d-12e6-42b6-b466-8d5588efa299%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages