Create a custom API wrapper

Posted 3 months ago by zfdeveloper

This is not directly related to Laravel but I'm going to use in a Laravel application.

I need to create a wrapper to an API and I wanted to create something similar to Eloquent.

For example, this API has an endpoint called plans, I wanted to create a wrapper to be something like Laravel models and Eloquent works:

$plan = new Plan;
$plan->save(); // it would call the post in the endpoint
// or ...
Plan::get('pl-299541'); // it would call get in the endpoint

I want to use Guzzle to make the requests easier.

I was wondering, how can I make something (chaining, static calls, etc) like this (as Laravel does with Eloquent)?

Thank you.

Please sign in or create an account to participate in this conversation.