简体   繁体   English

如何定义API端点

[英]How to define API Endpoints

I am designing an API to request information on an index with data that respect a certain JSON format. 我正在设计一个API,以使用符合某种JSON格式的数据来请求索引信息。

For the moment I only have data with type building, but other type could be coming, ie.: : 目前,我只有具有类型构建的数据,但是其他类型可能会出现,即:::

example data #1 :
"type": "building",
"id": "1",
"address" : "1 test",
...
"buildingType": "private",
"buildingSubType: "house"

example data #2 :
"type": "building",
"id": "2",
"address" : "100 test",
...
"buildingType": "corporate",
"buildingSubType: "restaurant"

example data #3 :
"type": "building",
"id": "3",
"address" : "200 test",
...
"buildingType": "government",
"buildingSubType: "hr services"

When I began the data was simpler with less types and subtypes so building the API endpoints was simple, but with time comes complexity and I want to define my api to be the more futureproof in regards to new data coming 当我开始时,使用较少的类型和子类型使数据更简单,因此构建API端点很简单,但是随着时间的流逝而变得复杂,我想将自己的api定义为对新数据的适应性更高

In respect to REST and future API Documentation here is what I got and would like to validate : 关于REST和将来的API文档,这是我得到的并且想要验证的内容:

/buildings - Returns all buildings entries
/buildings/{id} - Returns a specific building entry
/buildings/buildingTypes - Returns all buildingTypes
/buildings/buildingTypes/{name} - Returns building entries with the specified buildingType
/buildings/buildingTypes/{name}/buildingSubTypes - Returns all buildingSubTypes for the specified buildingType
/buildings/buildingTypes/{name}/buildingSubTypes/{name} - Returns building entries with the specified buildingType and buildingSubType

For 2 I will add query-string parameters to filter more precisely like : /buildings/buildingTypes/corporate?states=NY /buildings/buildingTypes/corporate/buildingSubTypes/restaurant?state=NY 对于2,我将添加查询字符串参数以进行更精确的过滤,例如:/ buildings / buildingTypes / corporate?states = NY / buildings / buildingTypes / corporate / buildingSubTypes / restaurant?state = NY

In respect to REST and future API Documentation here is what I got and would like to validate 关于REST和将来的API文档,这是我得到的并且想要验证的内容

REST doesn't care what spellings you use for your URLs, or how you organize your hierarchy of resources. REST不在乎您的URL使用什么拼写,也不在乎如何组织资源层次。

URL spelling conventions are for human convenience only -- they are no more important to the correctness of an API than the spelling of variable names. URL拼写约定仅是为了人类方便-它们对API的正确性没有比对变量名的拼写更重要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM