Why does spray routing formFields take a val instead of a type

112 Views Asked by At

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?

0

There are 0 best solutions below