4 ms·
I do appreciate the structural parity that this has with Laravel's Eloquent ORM models--that is, a class to represent a specific database resource. It makes API
by spheroidmethod 5y ago
I do appreciate the structural parity that this has with Laravel's Eloquent ORM models--that is, a class to represent a specific database resource. It makes API requests feel like a close analogue to that Laravel-esque functionality.
That said, REST API endpoint are effectively just functions--you pass in params, you get a response. They only have a single operation possible on them, unlike ORM models which can do many things.
Whenever I've implemented a custom API client in PHP, boring old OOP seems to solve the problems stated in the article reasonably well:
class ApiConsumer {
function __construct($baseUrl, $credentials);
function operationFoo($paramOne, $paramTwo): FooResponse;
function operationBar($paramOne, $paramTwo): BarResponse;
}