ReadyAPI is a PHP module to create REST API quickly
Import with Git :
git clone https://github.com/Olafr9500/ReadyAPI.git <your Project>/api
And get the dependencies and build the autoload with Composer :
composer install
The autoload will be done automatically via composer script.
In your database, make sure each table has a primary key in the first position.
-
Create an object in the folder
database
with the same name as your database. You can copy the filedatabase/databaseSample.php
and rename it. -
In the construct function, choose the host name, the database name and the identifiers
parent::__construct("<Name_Server>", "<Name_DataBase>", "<Username>", "<Password>");
The connector type is defined in the extends of the database object.
class DatabaseSample extends DatabaseMySql
You must have added a database object before performing this method.
composer add <NameObject> <DatabaseName>
-
Create an object in the folder
object
with the same name as your table. You can copy the fileobject/sampleObject.php
and rename it. -
Rename the object's class name to that of your table.
class SampleObject extends ObjectMySql
-
Add for each column a public variable in the object.
public $variable1; public $variable2; public $variable3;
-
In the construct function, add the table name, the list of all column names and the list of all new column.
parent::__construct($db, "sampleObject", ["id", "variable1", "variable2", "variable3"], ["id", "variable1", "variable2", "variable3"]);
Leave "id" in the first position
-
Write the "isEmpty" and "isDataCorrect" functions so that they correspond to the specifics of your variables.
-
Copy the folder
sampleObjectMySql/
and rename it with the name of your table. -
In each file of the folder, rename the calls of the file or of the sample class by that of your table.
include_once '../object/sampleObjectMySql.php'; ... $sample = new SampleObject($database->conn);
-
In the file
config/static.php
, change the$SECURE_API
constant from true to false.public static $SECURE_API = true;
-
After writing your objects, build the application to take them into autoload.
composer build
Make pull requests to help the project :D
Olafr9500
Copyright © 2021, Olafr9500. Released under the MIT License.