I have 4 levels of response based on URL. So for:
* GET on /abc
-> response should be abc
* GET on /abc/def
-> response should be def
* GET on /abc/def/ghi
-> response should be ghi
* GET on /abc/def/ghi/jkl
-> response should be (surprisingly) jkl
So my question is how to design that kind of request-response property with Spray.io?
I know that using pathPrefix
with path
is possible but that is only for two levels?
With that kind of approach it should look something like:
val route = {
path("/abc") {
// complete with response 'abc'
} ~
path("/abc/def") {
// complete with response 'def'
} ~
path("/abc/def/ghi") {
// complete with response 'ghi'
} ~
path("/abc/def/ghi/jkl") {
// complete with response 'jkl'
}
}
Is there any way to "nest paths"? I know this is not working but just an idea like:
val route = {
path("/abc") {
// complete with response 'abc'
'sub'path("/def") {
// complete with response 'def'
'sub'path("/ghi") {
// complete with response 'ghi'
'sub'path("/jkl") {
// complete with response 'jkl'
}
}
}
}
}
Or any other proper way of nesting paths?
Best, zmeda
path("abc" / "def" / "ghi")
etc. – LarrylarspathPrefix
as deep as you want, just make sure to usepath
on the innermost level. – Larrylars