hlagvankar
hlagvankar

Reputation: 319

Scala PLAY same routes

I have same routes in routes file but their action is different as shown

GET         /counts                                 controllers.Application.getAllCountsByFeature(features)
GET         /counts                                 controllers.Application.getAllCounts()

I'm calling both routes as

http://localhost:9000/segments/counts?features=feature_1,feature_2-feature_3
http://localhost:9000/segments/counts

But it's not working. I want play to recognize which route is called based on query string. If query string is provided then it should hit getAllCountsByFeature method and so on.

Is there any way? I'm using Play 2.5.9

Upvotes: 1

Views: 115

Answers (1)

Andriy Kuba
Andriy Kuba

Reputation: 8263

Use one route with optional parameter

GET         /counts                                 controllers.Application.getAllCountsByFeature(features: Option[String])

and then

def getAllCountsByFeature(features: Option[String]) = Action {
  features match{
    case Some(f) => //..
    case None => getAllCounts()
  }
}

Upvotes: 2

Related Questions