google-app-enginedartprotorpcclient-library

Support for query parameters in Dart for Google Endpoints?


I have a Dart application that's getting data from a custom Google endpoint. I'm using discoveryapis_generator to generate the client library. I would like to issue a query like the following:

import endpoints_api.dart as EndpointsApi;
api = new EndpointsApi.MyApi();
api.photos.list(api.Photo.post_id == "post1");

endpoints_api.dart is the client library generated by discoveryapis_generator generate.dart. MyApi is my custom endpoints API, and photos is one of its services. I think Photo is an endpoints model class which has an instance property post_id.

Issuing the request results in an error to the effect that Photo has no static getter "post_id". This is close to how to the syntax of a query in the Python API, so it was the only way I could think of to specify it here.

I don't know what else might be helpful in describing my request. Hopefully it is self-evident. There's an active enhancement described here, but it seems to refer to limiting the fields, rather than items, in the response.

Update:

Poking around in the client library, I found the source for the list methods. It certainly looks like query parameters are supported. But it seems to me that it's not entirely correct. The formal parameter list contains the query parameters specified in the API surrounded by braces:

async.Future<PhotoCollection> list({core.String postId, core.String regionId}) {...

But in the method body, there's the following:

    if (regionId != null) {
  _queryParams["region_id"] = [regionId];

Are the brackets in [regionId] to extract region from the parameter list?

I pulled the braces out of the parameter list. Since I only ever expect to query by postId, that's the only parameter:

async.Future<PhotoCollection> list(core.String postId) {...

Voila. I can now add a parameter to the query by just specifying its value in the call:

    api.photos.list("post1");

Solution

  • If you wrap the parameters of a method in curly braces, you make them optional.

    So you can still use your method with the given signature. You just have to add the name of the parameter you want to pass:

    api.photos.list(postId: "post1");