Siva Kumar Siva Kumar - 1 year ago 374
Scala Question

How to read query parameters in akka-http?

I know akka-http libraries marshal and unmarshal to class type while processing request.But now, I need to read request-parameters of

request. I tried
method and It is returning
type but i need those values as strings types

I check for answer at below questions.

  1. How can I parse out get request parameters in spray-routing?

  2. Query parameters for GET requests using Akka HTTP (formally known as Spray)

but can't do what i need.

Please tell me how can i extract query parameters from request. OR How can I extract required value from

Request URL


Get method definition

val propName = parameter("key")
val propValue = parameter("value")

My method declarations

def deleteSetting(name:String,value:String): Future[String] = Future{

Answer Source

For a request like http://host:port/path?key=authType&value=Basic345 try

path("path") {
  get {
    parameters('[String], '[String]) { (key, value) =>
      complete {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download