A simple RESTful API PHP without Frameworks, to help you to understand the concepts and the structure used. This way, you can use this example to develop your own API.
- Clone/download this folder to your computer.
- Save this folder in your Apache root directory.
- Access the DB folder and use the api_database.sql file to create your database.
- Change the connection.class.php file in api\connection path, if it's necessary.
You can use the API from a web front-end application, mobile app and also using the app called Postman in Chrome (you can download it in Chrome's Web Store using this [link] (https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?utm_source=chrome-ntp-icon)). Here i'm using the Postman to exemplifyed the use of the API.
We have 4 methods of access the API:
- GET
- POST
- PUT
- DELETE
GET method
(used to return an existing client): It's accessed using the URL http://localhost/API_Restful/api/client/(existing client id) as in the following example:
POST method
(used to include a new client): It's accessed using the URL http://localhost/API_Restful/api/client/ and passing as parameter (name, age and gender) as in the following example:
PUT method
(used to alter an existing client): It's accessed using the URL http://localhost/API_Restful/api/client/(existing client id) and passing as parameter (name, age and gender) as in the following example:
DELETE method
(used to delete an existing client): It's accessed using the URL http://localhost/API_Restful/api/client/(existing client id) as in the following example:
APIs are a great way to separate the back-end from the front-end of your application, this also makes it possible to develop for different kinds of platforms without change your back-end application and without rewrite your code in differents programming languages. For example: You can have a web application that access an API and develop a mobile application that will access the same API using the same routes. Isn't it awesome?