HappyCoder
HappyCoder

Reputation: 6155

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

What is the correct way to setup GET and POST services in ApiGility?

Currently, if I am setting up a GET service, I will include the variable I require in my route:

/api/verify/merchant[/:merchant_code]

And if I wish to setup a POST service, my route becomes:

/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:

/api/verify/merchant[/:merchant_code]

and add a merchant_code field as well...

Is this the correct way to setup the routing for this?

Upvotes: 0

Views: 213

Answers (1)

Wilt
Wilt

Reputation: 44326

In general you POST your new entities on the collection endpoint so in your case /api/verify/merchant. The server will respond with a new resource with a self href for the newly created Merchant. This href will be formatted like /api/verify/merchant[/merchant_code] where merchant_code will be the identifier for the newly added Merchant resource.

Sending a POST request to /api/verify/merchant[/merchant_code] is not necessary/valid. 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).

Upvotes: 2

Related Questions