I have defined methods as getJobByID and getJobByName in scala , now I am able to pass the Id parameter during the GET call as
val route = (path("dataSource"/LongNumber) & get){ id =>
complete(getJobById(id).map(_.asJson))
}
Now I want to get all jobs by name in similar fashion but didn't found any directive which can be used to get the Job name as the parameter and use it to find all job names. Do we have any solution or work around for this?
The Segment
path matcher will extract a String
value from the path and pass it on as a function argument:
val strRoute : Route =
get {
path("dataSourceByName" / Segment) { jobName : String =>
...
}
}
You can do it this way as well for String.
def getRoute : Route = get {
path("dataSourceByName") {
parameters('name.as[String]) {
(name) =>
...
}
}
}
Similarly for Int instead of as[String]
do as[Int]
P.S. : For 'as' to run import following statement:
import akka.http.scaladsl.server.Directives._
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With