RejectedSoftware Forums

Sign up

GET params

Hello!

I was searching for how to send GET params.

I saw some nice functionality in the rest.d module which converts JSON to a querystring for GET requests and otherwise writes it to the body.

Is this type of functionality also available outside rest.d?

Json request(HTTPMethod verb, string name, Json params, bool[string] param_is_json, in ref InetHeaderMap hdrs) const
{
...
  if ((verb == HTTPMethod.GET || verb == HTTPMethod.HEAD) && params.length > 0) {
    auto query = appender!string();
    bool first = true;
    foreach (string pname, p; params) {
      if (!first) {
        query.put('&');
      }
      else {
      first = false;
    }
  filterURLEncode(query, pname);
  query.put('=');
  filterURLEncode(query, param_is_json[pname] ? p.toString() : toRestString(p));
  }
  url.queryString = query.data();
}
...

if (verb != HTTPMethod.GET && verb != HTTPMethod.HEAD) {
  req.writeJsonBody(params);
}

Re: GET params

On Sat, 13 Dec 2014 20:40:42 GMT, Angst wrote:

Hello!

I was searching for how to send GET params.

I saw some nice functionality in the rest.d module which converts JSON to a querystring for GET requests and otherwise writes it to the body.

Is this type of functionality also available outside rest.d?

There's vibe.web.web which implements functionalities similar to vibe.web.rest. In addition, the formatting code would be quite straightforward to copy.

(Shameless plug)
I write a similar code that might be what you're looking for: https://github.com/Geod24/vibe.d/blob/2fa7188286c8b85c09e7ecc03400f5c51f558150/source/vibe/web/rest.d#L415