mevdschee / php-crud-api

Single file PHP script that adds a REST API to a SQL database

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Suggestion to modify response JSON root Key (records)

Ghenimi opened this issue · comments

Hello,

Currently, the root key of the response JSON is always set to "records". I would like to suggest a modification in the root key to reflects the last sub-URL (the name of the table being accessed). For instance, if the URL entered is "site.com/api/records/menu", instead of "records", it would be more intuitive and beneficial to have "menu" as the root key in the response JSON.

This adjustment would facilitate clearer and more contextually relevant data handling, such as accessing "menu.id" directly rather than "records.id" in the code, thereby enhancing the API's usability and developer experience.

Thank you so much for your exceptional work on this project. Your dedication and effort are truly appreciated!

This adjustment would facilitate clearer and more contextually relevant data handling, such as accessing "menu.id" directly rather than "records.id" in the code, thereby enhancing the API's usability and developer experience.

Most people have requested leaving out the "records" property in the response mixing the pagination properties with the data.

For instance, if the URL entered is "site.com/api/records/menu", instead of "records",

This seems to be achievable through the customization.afterHandler, by modifying the response and changing its root key to the $tableName.