1

I am trying to set up a basic server using spray routing and would like to use a type to represent one of the forms PUTs.

I am using the formFields('some, 'fields).as(Thing) notation as described in the documentation

At first glance I assumed .as was taking taking a type and instantiating an object of that type using the input defined in fromFields.

My example was constructed like this:

type UpdatePasswordRequest = Tuple3[String, String, String]

startServer(interface, port) {
  path("user" / IntNumber) { userEmail =>
    put {
      formFields('password, 'password2, 'key).as(UpdatePasswordRequest) { req =>
        //...
      }
    }
  } 
}

After getting the rather confused error that it couldn't resolve the symbol UpdatePasswordRequest I changed it from a type to a val and it at least compiles.

What is happening here? Why is it expecting a val? Can you even pass a type as a parameter to a function?

GoldenFish
  • 217
  • 2
  • 9
  • Short answer: you don't pass the type but a constructor, i.e. a function that let's you create an instance from constructor arguments. So, if you would pass `Tuple3[String, String, String]` it would just be a short form of `Tuple3[String, String, String](_, _, _)`. Btw. using Tuple3 with `as` doesn't seem particularly useful as you can also just write `formFields('password, 'password2, 'key) { (pass, pass2, key) => /* use those in this block */ }` (*EDIT*: fixed the previous code). – jrudolph Jul 17 '15 at 16:22
  • Thanks, add it as an answer and I would accept it – GoldenFish Jul 18 '15 at 19:28

0 Answers0