Simple change to allow for APIs that do not singlarize/pluralize endpoints...
empower-josh opened this issue · 1 comments
empower-josh commented
I am using an API that uses the same endpoint for single entity references as it does for multiple entity references. IE. the endpoint is /users/ regardless of whether I am fetching one by ID, or all records. This seemed to pose a challenge for php-api-wrapper. I did find a simple fix though:
in Model.php:
public function getEntities(): string
{
+++ if ($this->doNotPluralize) {
+++ return $this->entity;
+++ }
if (substr($this->entity, -1) === 'y') {
return rtrim($this->entity, 'y').'ies';
}
By adding this, then setting $entity = 'users', and adding 'protected $doNotPluralize = 1' to my model class, it keeps php-api-wrapper from munging the entity name when constructing the uri for the endpoint.
empower-josh commented
DOH. Turns out that it worked as expected by simply using the plural form form of the entity name without these changes.