Tom Russell Tom Russell - 8 months ago 64
Dart Question

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(); == "post1");

is the client library generated by discoveryapis_generator
is my custom endpoints API, and
is one of its services. I think
is an endpoints model class which has an instance property

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.


Poking around in the client library, I found the source for the
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
to extract
from the parameter list?

I pulled the braces out of the parameter list. Since I only ever expect to query by
, 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:"post1");

Answer Source

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: "post1");