Apigility is an open source project to create complete RESTful (and RPC) API in PHP. Using Apigility you can drastically reduce the amount of time needed to develop a web API with a full range of features: versioning, hypermedia links, documentation, filtering, validation, OAuth2 authentication, etc.
The installation of Apigility is super easy, just one command to execute in your terminal:
curl -sS https://apigility.org/install | php
or, if don't have curl installed:
php -r "readfile('https://apigility.org/install');" | php
This command installs Apigility on your computer. After a couple of minutes, the installation ends with the execution of the Admin web interface, running at http://localhost:8888. If you open this URL you will see the welcome screen.
You can create your RESTful services using this UI, just click on the "Get Started!" button, select the "APIs" voice in the menu and click on the "Create New API" button.
You need to enter a name for the API, for instance "Test". After the creation of the API you can create REST or RPC services in it. For Apigility, an API is a container of web services. You can have as many APIs you want, and each API can have as many web services you desire.
To create a REST service, select the "REST Services" voice in the menù on left and click on "Create New REST Service", on the right.
Apigility will ask for the service's name, for instance imagine we want to expose user's data, write "User" and click on "Create Code-connected REST Service".
We basically done, Apigility builds the skeleton classes that implement the User service with some default values, such as the URL that will be /user[:/user_id].
If you go in the "Source Code" tab, you will see the files that has been created, a Collection Class, an Entity Class and a Resource class.
You can try the REST service from a client, for instance requesting GET /user (using curl):
You will get an empty response, actually a "Method not allowed" error because we didn't insert the PHP code to retrieve the user's data.
In the next articles we will show how to do that.