Download the PHP package codecasts/restinga without Composer
On this page you can find all versions of the php package codecasts/restinga. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download codecasts/restinga
More information about codecasts/restinga
Files in codecasts/restinga
Package restinga
Short Description Easily Create REST API Clients for your PHP Applications
License MIT
Informations about the package restinga
Restinga
Easily Create REST API Clients for your PHP Applications
What it is?
Restinga is tool to help you building REST Clients for your chosen API's.
Why?
Well, sometimes the PHP Clients that companies provides sucks, you know it. Sometimes they are even more hard to use than CURLing the API itself. We've built this package to help you when that happens.
Quick Start
Before starting, you need to install Restinga as a project dependency. you can do that by running:
composer require codecasts/restinga ~1.0
So now we can move defining your services.
1 - Creating a Descritor for the Desired Service
Let's take for example Digital Ocean API, Restinga is not designed to handle Authorization it self so you should already have a person token or user token.
Start by Creating a file that will describe where to find and how to authorize the requests, you can easily do that by extending the Codecasts\Restinga\Service\Descriptor
class.
After creating this file, you need to Register it on the Restinga Container, so it can be used by your resource classes later.
You can do that by using:
2 - Defining your resources
Ok, now that we have everything in place, let's create our first resource.
Let's say we want to handle the digital ocean droplets, right? so, we'll define a Resource (by extending Codecasts\Restinga\Data\Resource
) to handle it.
3 - Using the Defined Resource
Ok, now that we defined your resource, we can start using it.
Creating a Droplet
Error when creating a Droplet
Finding a resource by it's identifier
Updating an Resource
The General idea is the same:
Deleting an Resource
Works the same way:
Nested Resources All good for an example so far, but real world api has nested objects. That's ok, let's see how to handle it.
Digital Ocean has Domain and Domain Records, let's create those two resources and link them.
Domains:
DomainRecord:
Those two are created but not linked yet, let's do that by creating a record()
method inside the Domain resource class:
Now, we can use it this way:
Other method also works the same way, for example, to find and update a record