A customizable Representational State Transfer (REST) Application Program Interface (API) designed to provide a quick set of tools for developers to quickly build their own API.
Note: this repository is currently under construction.
- Supports basic CRUD (Create Read Update Delete) operations
- Supports HTTP requests GET POST PUT and DELETE
- Can interact with anything that can send an HTTP request
- Data is returned in JSON (JavaScript Object Notation) format
- MySQL database preset
- Protection against MySQL injection
- Interfacing with new tables is as simple as adding new models
- Customizable controllers to interface with other databases
REST-UP can be installed using composer:
composer require maxcarter/restup
OR by simply extracting all files to the desired location in your website directory:
git clone https://github.com/maxcarter/REST-UP.git
rsync -r REST-UP/* Path/To/Destination
Once installed you should be able to see the welcome text at: http://YourDomain.com/PathToAPI
Another way to test the API is to install the Chrome Extension Postman then open the app and send http requests to http://YourDomain.com/PathToAPI
.
- PHP v5.6+
- MySQL v5.6+
The sample code is based on the following MySQL table:
CREATE TABLE `person` (
`id` int NOT NULL AUTO_INCREMENT,
`Name` varchar(255) DEFAULT NULL,
`City` varchar(255) DEFAULT NULL,
`Email` varchar(255) DEFAULT NULL
);
To insert sample data into this database:
INSERT INTO `person` (`Name`, `City`, `Email`) VALUES
('Clark Kent', 'Smallville', 'superman@justiceleague.com');
To configure this REST-API to work with your database follow these steps:
- Modify
config.php
with the appropriate credentials. - Create your own DTO (Data Transfer Object) and place it in the
models
directory. (see models/person.php for a sample DTO)
This REST API can be customized to work with different databases. The default preset is MySQL, however, you can create your own database controller to interface with different databases and implement custom functionality.
To create a custom controller follow these steps:
- Create a new PHP file to implement the Controller class (see controllers/mysql.php for an example)
- Ensure your class implements the required CRUD functions.
- Modify config.php to include your controller's file name and database credentials.
/**
* Create a new entry
* @param [object] - The entry to be inserted
* @return [object] - JSON result of insertion
*/
postValue($data);
/**
* Read all entries
* @return [array] - An array of objects
*/
getValues();
/**
* Read a single entry
* @param [int] - The unique id of the entry
* @return [object] - The requested entry
*/
getValue($value);
/**
* Update an entry
* @param [object] - The entry to be updated
* @return [object] - JSON result of update
*/
putValue($data);
/**
* Delete a single entry
* @param [int] - The unique id of the entry
* @return [object] - JSON result of deletion
*/
deleteValue($value);
- Live Demo
- HTTP request documentation
- More database presets