Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set HTTP GET Parameters in Finagle

Tags:

finagle

In Finagle, how do I create a request an HTTP GET request with parameters in a safe, clean way?

val request = RequestBuilder()
  .url("http://www.example.com/test")
  .addParameter("key", "value")   // this doesn't exist
  .buildGet()
request    // should be a GET request for http://www.example.com/test?key=value
like image 321
duckworthd Avatar asked Aug 14 '13 02:08

duckworthd


People also ask

How do I configure finagle clients and servers?

The modern way of configuring Finagle clients or servers is to use the Finagle 6 API, which is generally available via the with -prefixed methods. For example, the following code snippet creates a new HTTP client altered with two extra parameters: label and transport verbosity.

Should I use the Finagle expert-level API?

The expert-level API requires deep knowledge of Finagle internals and it’s recommended to avoid it unless you’re sure of what you’re doing or the corresponding configuration has not yet been exposed through with -prefixed methods.

What are HTTP parameters and how to use them?

When the HTTP method is used to request certain resources from the web server, the client also sends some parameters to the web server. These parameters are in a pair of names and their corresponding values, which are called HTTP parameters. Let us now discuss each of them in detail.

How to do HTTP GET request with parameters in angular?

To do http get request with parameters in Angular, we can make use of params options argument in HttpClient.get () method. options: { headers?: HttpHeaders | { [header: string]: string | string []}, observe?: 'body' | 'events' | 'response', params?:


2 Answers

You can use the confusingly-named Request.queryString:

val request = RequestBuilder()
  .url(Request.queryString("http://www.example.com/test", Map("key" -> "value"))
  .buildGet()
like image 52
Robin Green Avatar answered Sep 24 '22 17:09

Robin Green


The arguments passed to RequestBuilder.url() are expected to be fully-formed, so Finagle doesn't provide any way to tack on more query parameters.

One way to solve this would be to construct a URL object outside of the context of the RequestBuilder chain. You could define your query parameters in a Map, turn it into a query string, and then concatenate it to the base URL:

val paramStr = Map("key" -> "value", ...) map { case (k, v) =>
  k + '=' + v
} mkString("?", "&", "")

val request = RequestBuilder.safeBuildGet(
  RequestBuilder.create()
    .url("http://www.example.com/test" + paramsStr)
)

Note that you'll need to encode any query parameters that you specify in the Map.

like image 23
Evan Meagher Avatar answered Sep 24 '22 17:09

Evan Meagher