Comment

Comment by spheroidmethod

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;
  }

No comments yet

Be the first to share your thoughts.

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton