【问题标题】:Optional query params aqueduct可选查询参数 aqueduct
【发布时间】:2019-04-11 23:16:51
【问题描述】:

翻遍documentation,没找到。

如何在 aqueduct 中创建一个可选的查询参数?

【问题讨论】:

    标签: aqueduct


    【解决方案1】:

    通过将参数包裹在大括号中:

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

    这在此处记录:http://aqueduct.io/docs/http/resource_controller/#optional-bindings

    【讨论】:

    • 我认为你给我看的链接的整个部分(我已经去过一百万次了)应该用你的第一句话代替。这就是整个部分需要说明的关于可选绑定的全部内容。谢谢!
    【解决方案2】:

    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);
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2020-12-22
      • 1970-01-01
      • 2021-02-02
      • 2018-09-23
      • 2020-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-01
      相关资源
      最近更新 更多