Kunal
Kunal

Reputation: 11

found : spray.routing.Directive0 (which expands to) spray.routing.Directive[shapeless.HNil] required: spray.routing.Directive[shapeless.HList]

I need help. I am trying to use CURL to do HTTP POST & use spray routing along with parameters

curl -v -o UAT.json "http://*****/pvdtest1/14-JUL-2014?enriched=true" -H  "Content-Type: application/json" -d '{ "text": "Test", "username": "User" }'

My JSON Post is optional, means I can also get request as

curl -v -o UAT.json "http://*****/pvdtest1/14-JUL-2014?enriched=true"

In the routing if I use

 path("pvdtest1" / Segment) { (cobDate) =>
          (parameters('enriched.as[Boolean] ? false) & post) {
            (enriched) => {
              println(" inside post")
              entity(as[Message]) { message =>
                println(" inside post 1")
                logger.debug("User '{}' has posted '{}'", message.username, message.text)

above code works file

but if I try to make POST optional, it does not work

 path("pvdtest1" / Segment) { (cobDate) =>
          (parameters('enriched.as[Boolean] ? false) | post) {
            (enriched) => {
              println(" inside post")
              entity(as[Message]) { message =>
                println(" inside post 1")
                logger.debug("User '{}' has posted '{}'", message.username, message.text)



Error:(166, 56) type mismatch;
 found   : spray.routing.Directive0
    (which expands to)  spray.routing.Directive[shapeless.HNil]
 required: spray.routing.Directive[shapeless.HList]
Note: shapeless.HNil <: shapeless.HList, but class Directive is invariant in type L.
You may wish to define L as +L instead. (SLS 4.5)
          (parameters('enriched.as[Boolean] ? false) | post) {

Can someone please help in resolving the issue?

Upvotes: 1

Views: 533

Answers (1)

Mark
Mark

Reputation: 1181

The problem is that the | method in Spray requires that both sides are of the same kind. parameters provides one Boolean, post no value. The & method concats the two directives, so they may may be of different kinds.

You could change that line to the following to allow both get and post, and capture the enriched parameter:

(get | post) { (parameters('enriched.as[Boolean] ? false)

Upvotes: 2

Related Questions