Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
关系数据库如何使用RESTAPI?_Rest_Api_Relational Database - Fatal编程技术网

关系数据库如何使用RESTAPI?

关系数据库如何使用RESTAPI?,rest,api,relational-database,Rest,Api,Relational Database,我试图理解RESTAPI在处理关系型规范化数据库时是如何工作的。例如,给定表Customer、Order和OrderType: Customer ID Name Address Order ID Amount TypeId CustomerId Order Type ID Desc 如果我想查找给定客户的所有订单信息,我会执行类似于url/customers/:customerId/orders;在API中,它将处理对表执行连接以返回这

我试图理解RESTAPI在处理关系型规范化数据库时是如何工作的。例如,给定表
Customer
Order
OrderType

Customer
   ID
   Name
   Address

Order
   ID
   Amount
   TypeId
   CustomerId

Order Type
   ID
   Desc
如果我想查找给定客户的所有订单信息,我会执行类似于
url/customers/:customerId/orders
;在API中,它将处理对表执行连接以返回这样的响应

{
   "orderNumber": 123,
   "type": "online",
   "customer": "john doe",
   "amount": "500"
},
{
   "orderNumber": 124,
   "type": "in-store",
   "customer": "jane doe",
   "amount": "100"
}

对吗?或者我需要单独调用API,比如
url/customers/:customerId
url/orders/:customerId
,和
url/orderType/:typeId
,然后在前端组装信息吗

如果您在前端组装信息,您将失去关系数据库的大部分好处,并且必须编写大量代码,而不是一行sql。您可以根据要执行的特定任务来设计API路由,这并不取决于应用程序体系结构和所使用的技术堆栈。

因此,REST API的概念对我来说仍然非常陌生。如果我理解正确,我将设置(例如)
url/customer/:customerId/orders
,这样API中的这个特定路由将从我问题的第一部分返回组装好的对象(格式为JSON)?正如我如何使用SQL语句从客户c中选择*,其中c.id=1内部连接订单o on o.CustomerId=c.id;对的