How to make one of the REST API parameter as optional


(Shubhada) #1

Hi all,

I am using Scala with Lagom and want to make one of the input parameter as optional in the path of the rest Call method. Suppose the service descriptor is as below:

trait CounterService extends Service {

  def getCountsOfRecords(Id: String, count: Int):
                ServiceCall[NotUsed, JsValue]

  override final def descriptor = {		
    import Service._
    named("Counts")
    .withCalls(
      restCall(GET,
        "/userId/:id/topcounts/:count", getCountsOfRecords _),
      restCall(GET,
        "/userId/:id/topcounts", getCountsOfRecords _),
    )
    .withAutoAcl(true)
  }
}

Here, I want to use the the same handler for two different purposes,

  1. Show top 10 records by default
  2. Show top of records

For example:

  1. /userId/12/topcounts - Should return default top 10 records
  2. /userId/12/topcounts/20 - Should return top 20 records

Could you please suggest me the way I should do it?

Thanks in advance.


(Shubhada) #2

Could anyone please give your inputs.

Thanks.