简体   繁体   English

ZF2和Apigility-设置GET和POST RPC服务的正确方法

[英]ZF2 & Apigility - Correct way to setup GET and POST RPC services

What is the correct way to setup GET and POST services in ApiGility? 在ApiGility中设置GET和POST服务的正确方法是什么?

Currently, if I am setting up a GET service, I will include the variable I require in my route: 当前,如果要设置GET服务,我将在路由中包含所需的变量:

/api/verify/merchant[/:merchant_code] / api / verify / merchant [/:merchant_code]

And if I wish to setup a POST service, my route becomes: 如果我想设置POST服务,我的路线将变为:

/api/verify/merchant / api / verify / merchant

And I add a merchant_code 'field' 然后添加一个商人代码 “字段”

And if I want my route to accept both POST and GET, I then do this: 如果我希望我的路线同时接受POST和GET,则可以执行以下操作:

/api/verify/merchant[/:merchant_code] / api / verify / merchant [/:merchant_code]

and add a merchant_code field as well... 并添加一个商人代码字段...

Is this the correct way to setup the routing for this? 这是为此设置路由的正确方法吗?

In general you POST your new entities on the collection endpoint so in your case /api/verify/merchant . 一般来说,你POST在集合端点的新的实体,以便在您的情况/api/verify/merchant The server will respond with a new resource with a self href for the newly created Merchant . 服务器将使用新创建的Merchant的self href作为新资源进行响应。 This href will be formatted like /api/verify/merchant[/merchant_code] where merchant_code will be the identifier for the newly added Merchant resource. 该href的格式将类似于/api/verify/merchant[/merchant_code] ,其中merchant_code将是新添加的Merchant资源的标识符。

Sending a POST request to /api/verify/merchant[/merchant_code] is not necessary/valid. 发送POST请求到/api/verify/merchant[/merchant_code]是不必要的/无效的。 You do GET , PATCH , DELETE or PUT requests on the endpoint of your Merchant resource depending on the action you want to perform (read, update, delete, replace). 您可以根据要执行的操作(读取,更新,删除,替换)在Merchant资源的端点上执行GETPATCHDELETEPUT请求。

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

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