Questions tagged [spray-routing]
36 questions
5
votes
2 answers
Spray Akka Json Unmarshalling
I've a problem about unmarshalling objects to Json via using spray - akka.
When i'd like to use actors that returns Future[List[Person]] , it doesn't work.
If i use dao object directly, it works.
Here are my codes:
PersonDao.scala
import…

Bilal ALP
- 111
- 8
5
votes
1 answer
Lazy formatted recursive JSON type can't be found as implicit value
I'm using Spray to build a REST API.
One of my JSON datatypes are recursive:
case class Container(id: String,
name: String,
read_only: Boolean,
containers: List[Container],
…

spydon
- 9,372
- 6
- 33
- 63
3
votes
1 answer
How do I chain routes (using `~`) which are the results of functions?
scala> import akka.http.scaladsl.server._; import Directives._
import akka.http.scaladsl.server._
import Directives._
Suppose I have two functions from some type (Int, say) to a Route:
scala> lazy val r1: Int => Route = ???
r1: Int =>…

oxbow_lakes
- 133,303
- 56
- 317
- 449
3
votes
0 answers
How to organize complex spray / akka http routes?
Does anyone know any good rules of thumb, or good articles about organizing complex routes?
My Service has a routing that spans over about 400 lines, and IntelliJ is not the only one that has problems parsing and navigating it (also me).
What is a…

Ákos Vandra-Meyer
- 1,890
- 1
- 23
- 40
2
votes
1 answer
Spray - deserializing optional query parameter
From spray.io documentation page:
color
extract value of parameter “color” as String
color.?
extract optional value of parameter “color” as Option[String]
amount.as[Int]
extract value of parameter “amount” as Int, you need a matching…

eugen-fried
- 2,111
- 3
- 27
- 48
2
votes
1 answer
How to aggregate akka-http routes using a trait?
I am trying to aggregate routes using a trait at runtime, so far I have
object SMController {
def aggregateRoutes(actorSystem: ActorSystem): List[Route] = {
val runtimeMirror = universe.runtimeMirror(getClass.getClassLoader)
val…

rojanu
- 1,592
- 5
- 20
- 34
2
votes
1 answer
Streaming dynamic content, with Spray Route
I am developing a web service that serves some relatively large files, each created dynamically at request time. In my case this is a ZIP archive file that contains a bunch of files, but I assume the same problem will occur with other types of…

yby
- 915
- 1
- 8
- 24
2
votes
0 answers
Spray routes - early reject?
My routing is similar to this:
pathPrefix("api") {
path("login") {
entity(as[LoginRequest]) { login =>
complete { ... }
}
} ~
pathPrefix("persons") {
pathEnd {
get { ctx => ctx.complete(model.getPersons) }
} ~
…

Ákos Vandra-Meyer
- 1,890
- 1
- 23
- 40
1
vote
2 answers
How can I convert Java object to Json in spray routing
I would like to know if there is any way to return Java object as Json String inside spray routing.
For now, I am converting my Java object (which is returned my UserActor) into Json using Jackson through a util class(JacksonUtil) created by…

dj_1993
- 93
- 1
- 8
1
vote
1 answer
spray-http redirect to other subdomain
I need to redirect all traffic without a subdomain to the www subdomain (e.g, foo.com->www.foo.com).
The code below is working, but i know redirecting code can be brittle and might bring security flaws.
Is this a proper way of achieving the above,…

raphaëλ
- 6,393
- 2
- 29
- 35
1
vote
1 answer
akka-http: How can I consume/hide an extracted value?
I am trying to write a directive that rejects non-ajax requests. The code below doesn't work obviously:
import akka.http.scaladsl.model.HttpHeader
import akka.http.scaladsl.server.Directive0
import…

muhuk
- 15,777
- 9
- 59
- 98
1
vote
0 answers
Spray routing - matched path value
We can use Pipe(|) for path matching in Spray for the use case of "OR" like below.
val route =
path("foo" | "bar" ) {
complete(??)
}
From above example, how to know the value originally it matched (From "foo" or "bar". Which one? ). I didn't…

jony
- 119
- 3
- 13
1
vote
0 answers
Nesting authorize directives in spray
It seems it is impossible to nest authorized directives in spray due to this line: https://github.com/spray/spray/blob/76ab89c25ce6d4ff2c4b286efcc92ee02ced6eff/spray-routing/src/main/scala/spray/routing/directives/SecurityDirectives.scala#L55
I'm…

Ákos Vandra-Meyer
- 1,890
- 1
- 23
- 40
1
vote
1 answer
Spray - Parsing forms with checkboxes
I am setting up a simple API part of which accepts POST requests via form submission. The form requires the user to select one or more checkboxes all sharing the same name e.g.
1
vote
2 answers
Case insensitive parameter parsing in Spray routing
I would like to make parameter parsing in Spray routing case insensitive. For example:
val route: Route = {
(path("search") & get) {
parameters('pagesize.as[Int] ?, 'appId ?) { (pageSize, appId) =>
...
}
}
}
In this route, I…

Rahul Singhai
- 1,299
- 15
- 27