检索REST中嵌套查询对象筛选的数据

检索REST中嵌套查询对象筛选的数据,rest,restful-architecture,restful-url,Rest,Restful Architecture,Restful Url,我需要通过以下方式检索产品: 查询(搜索词) 区域 半径 坐标 纬度 经度 只发送半径而不发送坐标是非法的,反之亦然。 只发送纬度而不发送经度是非法的,反之亦然 URL和查询参数在REST中应该如何使用?您可以使用查询参数按查询字符串进行搜索,使用URI参数按区域进行搜索 在任何情况下,您都应该记录您的API。使用RAML的文档示例如下: #%RAML 1.0 title: test version: v1 /products: /by-search-and-by-area/{r

我需要通过以下方式检索产品:

  • 查询(搜索词)
  • 区域
    • 半径
    • 坐标
      • 纬度
      • 经度
只发送半径而不发送坐标是非法的,反之亦然。 只发送纬度而不发送经度是非法的,反之亦然


URL和查询参数在REST中应该如何使用?

您可以使用查询参数按查询字符串进行搜索,使用URI参数按区域进行搜索

在任何情况下,您都应该记录您的API。使用RAML的文档示例如下:

#%RAML 1.0
title: test
version: v1
/products:
  /by-search-and-by-area/{radius}/{latitude}/{longitude}::
    get:
      queryParameters: 
        q:
          type: string
          minLength: 2
          example: laptop dell
          required: true
    uriParameters: 
      latitude: 
        type: number
        example: 25.45
        required: true
      longitude: 
        type: number
        example: 25.45
        required: true
      radius: 
        type: number
        example: 100
        description: radius in km
        required: true
    get:
      description: returns products by radius and latitude and longitude

为什么不使用RAML记录端点,然后使用url模板?@ConstantinGALBENU你能举个例子吗?举个什么例子吗?在restful应用程序中,url有点不相关,客户端不能将任何url硬编码到其请求中,但它/你可以使用
{templates}
进行过滤;但是,您必须将它们记录在raml文件中。这是一个如何在raml中实现我所描述内容的示例。我需要同时按查询和坐标进行搜索。我应该只能按查询和坐标进行搜索