nafas
nafas

Reputation: 5423

playframe work can't find the right route

I have a strange problem

this is what I have in routes files

GET     /path/list                          controllers.path.getPaths()
GET     /path/:id                           controllers.path.get(id:Int)

when I try to go <domain>/path/list the following error shows up:

For request 'GET /path/list' [Cannot parse parameter id as Int: For input string: "list"]

I also tried to change the order in routes file

GET     /path/:id                           controllers.path.get(id:Int)
GET     /path/list                          controllers.path.getPaths()

I still get the same error. so my question is

  1. isn't route supposed to match the first path that matches?
  2. what else could be the problem (e.g. java codes)?

Upvotes: 2

Views: 1261

Answers (1)

tgk
tgk

Reputation: 4116

From the code you've provided this should work. The routes are not ambiguous because (from Play documentation):

Many routes can match the same request. If there is a conflict, the first route (in declaration order) is used.

if your routes ordering looks like this:

GET     /path/list                          controllers.path.getPaths()
GET     /path/:id                           controllers.path.get(id:Int)

/path/list will match before attempting to extract/transform the id parameter id:Int from the path and throwing.

If you want Play to transform the incoming parameter into a specific Scala type, you can add an explicit type

The only way this would not work is if you attempted to visit a route that did not match list or was not an Int:

For request 'GET /path/lists' [Cannot parse parameter id as Int: For input string: "lists"]

Upvotes: 4

Related Questions