Download the PHP package laswitchtech/php-api without Composer
On this page you can find all versions of the php package laswitchtech/php-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download laswitchtech/php-api
More information about laswitchtech/php-api
Files in laswitchtech/php-api
Package php-api
Short Description REST API for php applications
License GPL-3.0-only
Informations about the package php-api
phpAPI - [DEPRECATED] - Use coreAPI instead
Features
- REST API
Why you might need it
If you are looking for an easy start for your PHP REST API. Then this PHP Class is for you.
Can I use this?
Sure!
License
This software is distributed under the GNU General Public License v3.0 license. Please read LICENSE for information on the software availability and distribution.
Requirements
- PHP >= 8.0
- MySQL or MariaDB
Security
Please disclose any vulnerabilities found responsibly – report security issues to the maintainers privately.
Installation
Using Composer:
How do I use it?
In this documentations, we will use a table called users for our examples.
Skeleton
Let's start with the skeleton of your API project directory.
- api.php: The api file is the entry-point of our application. It will initiate the controller being called in our application.
- config/api.cfg: The config file holds the configuration information of our API. Mainly, it will hold the database credentials. But you could use it to store other configurations.
- Controller/: This directory will contain all of your controllers.
- Controller/UserController.php: the User controller file which holds the necessary application code to entertain REST API calls. Mainly the methods that can be called.
- Model/: This directory will contain all of your models.
- Model/UserModel.php: the User model file which implements the necessary methods to interact with the users table in the MySQL database.
Models
Model files implements the necessary methods to interact with a table in the MySQL database. These model files needs to extend the Database class in order to access the database.
Naming convention
The name of your model file should start with a capital character and be followed by . If not, the bootstrap will not load it. The class name in your Model files should match the name of the model file.
Example
Controllers
Controller files holds the necessary application code to entertain REST API calls. Mainly the methods that can be called. These controller files needs to extend the BaseController class in order to access the basic methods.
Naming convention
The name of your controller file should start with a capital character and be followed by . If not, the bootstrap will not load it. The class name in your Controller files should match the name of the controller file.
Finally, callable methods need to end with .
Example
Configurations
The config file holds the configuration information of our API. Mainly, it will hold the database credentials. But you could use it to store other configurations. The configuration file must be stored in config/config.php. As this file is already being loaded in the bootstrap.
Example
API
The api file is the entry-point of our application. It will initiate the controller being called in our application. The file itself can be named any way you want. As long as you point your API calls to it. In our example we use api.php. This name is useful because it allows you to build a front-end using the index.php file and it also makes it obvious as the URL of your API.
Example
Calling the API
Once you have setup your first controller and model, you can start calling your api.
JavaScript Implementation
phpAPI comes packed with a JavaScript implementation. The class is available in /vendor/laswitchtech/php-api/dist/js/phpAPI.js.
Examples
For more example, look into the example folder.