【问题标题】:Nested query params with TeslaTesla 的嵌套查询参数
【发布时间】:2019-06-12 08:13:08
【问题描述】:

这是我要访问的 URL:

/example/?fields=*&filter[platform][eq]=111&order=date:asc&filter[date][gt]=1500619813000&expand=yes

我的代码:

  get("/release_dates",
      query: [
        fields: "*",
        order: "date:desc",
        expand: "games",
        filter: %{
          date: %{gt: unix_now},
          version_parent: %{not_exists: 1}
        }
      ]
    )

我正在尝试执行包含 filter[date][gt]=123123123123 类型查询参数的 Tesla GET 请求。

感谢您的帮助!

【问题讨论】:

  • 您发布的代码曾经如何与您声称尝试点击的查询相关联?特斯拉到底是谁?期望的结果是什么?您收到什么错误?

标签: get elixir query-parameters tesla


【解决方案1】:

如果我对您的理解正确,您想生成一个带有过滤器的 URI,用于过滤可变的“大于”时间戳。

根据您的初始示例,可以这样完成:

Tesla.get("/example/",
  fields: "*",
    filter: [
    platform: [
      eq: 111
    ]
  ],
  order: "date:asc",
  filter: [
    date: [
      gt: unix_now
    ]
  ],
  expand: "yes"
)

请注意,/example 是相对引用,只能使用基本 URI 解析。最好提供完整的 URI。

如果您想在 iex 控制台中试验 URI 生成器,您可以在项目目录中使用 iex -S mix,然后使用以下函数:

Tesla.build_url("/example/",
  fields: "*",
  filter: [
    platform: [
      eq: 111
    ]
  ],
  order: "date:asc",
  filter: [
    date: [
      gt: 123123123123
    ]
  ],
  expand: "yes"
) |> URI.decode()

【讨论】:

    猜你喜欢
    • 2021-01-14
    • 2019-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-19
    • 2012-09-07
    • 2018-06-13
    相关资源
    最近更新 更多