php-crud-api icon indicating copy to clipboard operation
php-crud-api copied to clipboard

PUT with Query Params

Open drveresh opened this issue 8 months ago • 3 comments

I need to update a record (PUT), but its endpoint should support more than one query parameters or conditions, how to achieve this?

For example, if there is an endpoint like "/records/comments/*", then I want to achieve like "/records/comments/?id=4&status=new" for PUT. Is this possible?

I tried this format "/records/comments?filter=id,eq,123&filter=status,sw,new", but didn't work, and got an error saying "{ "code": 1000, "message": "Route '/records/comments/' not found" }"

drveresh avatar Nov 23 '23 06:11 drveresh

Hi @drveresh, this is currently not supported. An update query will update one record and a delete query will delete one record (based on the primary key). This is by design to avoid people from accidentally overwriting too many (or all) records. I hope you understand. Kind regards, Maurits

mevdschee avatar Nov 24 '23 06:11 mevdschee

@mevdschee I agree, but it will just fundamentally limits its capabilities based on a single primary key. Technically, we can make this configurable option, and try to expand its use cases to update either single or more records, based on one or more fields.

drveresh avatar Dec 13 '23 11:12 drveresh

The HTTP semantics are specifed as a web standard such as RFC 9110. Based on this, the PUT method is expected to affect just one target resource or record.

While it may be possible to modify the API's behavior to allow the method to affect multiple records, doing so would basically make it non-standard and may cause unwanted side-effects for some users.

https://datatracker.ietf.org/doc/html/rfc9110#name-put

apps-caraga avatar Dec 21 '23 10:12 apps-caraga