【发布时间】:2019-04-11 23:16:51
【问题描述】:
翻遍documentation,没找到。
如何在 aqueduct 中创建一个可选的查询参数?
【问题讨论】:
标签: aqueduct
翻遍documentation,没找到。
如何在 aqueduct 中创建一个可选的查询参数?
【问题讨论】:
标签: aqueduct
通过将参数包裹在大括号中:
@Operation.get()
Future<Response> getAllCities({@Bind.header('x-api-key') String apiKey}) async
{}
这在此处记录:http://aqueduct.io/docs/http/resource_controller/#optional-bindings
【讨论】:
optional binding documention 给出了如何使用可选query string parameters 或headers 的示例。但是像//host.com/path/subpath 这样的 URL 呢?下面是简单的例子:
// 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);
}
}
【讨论】: