3

Went through the documentation, couldn't find any.

How does one make an optional query param in aqueduct?

KhoPhi
  • 9,660
  • 17
  • 77
  • 128

2 Answers2

4

By wrapping an argument in curly brackets:

@Operation.get()
Future<Response> getAllCities({@Bind.header('x-api-key') String apiKey}) async 
{}

This is documented here: http://aqueduct.io/docs/http/resource_controller/#optional-bindings

Joe Conway
  • 1,566
  • 9
  • 8
  • 1
    I think the entire section of the link you showed me (which I've been there a million times already), should be replaced by your first sentence. That's all that entire section needs to say about the optional bindings. Thank you! – KhoPhi Apr 12 '19 at 16:58
0

The optional binding documention gives examples how to use optional query string parameters or headers. But what about URL like this //host.com/path/subpath? Below the simple example:

// Dummy example class
class OptionalController extends ResourceController {
  @Operation.get()
  Future<Response> getItemsByDefault() => getItemsByCount(1);

  @Operation.get('count')
  Future<Response> getItemsByCount(@Bind.path('count') int count) async {
     return Response.ok(count);
  }
}
BambinoUA
  • 6,126
  • 5
  • 35
  • 51