25 Nov, 2017

How to create simple REST API in PHP

25 Nov, 2017

Dear Reader, let us we know that “How to create simple REST API in PHP with Live Demo“. So in this Tutorial, We Learn Step By Step  How to create simple REST API in PHP Process.

API stands for “Application Programming Interface”. It is a set of rules that allows one piece of the software application to talk to another. Those “rules” can include creating, read, update and delete operations.

REST stands for “REpresentational State Transfer”. It is a concept or architecture for managing information over the internet. REST concepts are referred to as resources. A representation of a resource must be stateless.

First, we see Snapshots for our REST API form using which we can fetch data

And you can also see Live Demo by click on bellow Demo button

Step 1:- First of all we need to create the database like php_demo

Step 2:- Now create a table “mobiles” in a database using the below SQL code

Step 3:- Now dump some data for table “mobiles” using bellow SQL code

Step 4:- Now we need to create a db.php file in our project in DB folder



and paste the below code

Step 5:- create index.php file in our project in API folder like “C:\xampp\htdocs\php_demo\api\index.php” and paste below code

Step 6:- Finally we need to create read.php file in our project like “C:\xampp\htdocs\php_demo\api\read.php” and paste below code

Step 7:- Now run your project, so we need to type in browser localhost/your_project_name/api/


http://localhost/php_demo/api/ then you can see the result as in below snapshot, you can Fetch data in using REST API by type value in the form and click on Find button


Congratulations you have successfully created Simple REST API in PHP, if you like this post and was helpful for you then share this post on social media and if you have any query then please contact us or comment below, Thanks.



  • TomasSmall December 05, 2017

    I have checked your site and i’ve found some duplicate content, that’s why you don’t rank high in google’s search results,
    but there is a tool that can help you to create 100% unique articles, search for: Boorfe’s tips
    unlimited content


    • Webpreparations Team December 22, 2017

      Thank you soo much for appreciating and best suggestions. 🙂


  • rardlem August 24, 2019

    Hello. And Bye.


    • WebPreparations Team August 25, 2019


      how we can help you??


  • rardlem December 09, 2019

    i am from Italy hello. Can you help me translate? /rardor


Leave a comment:

Your email address will not be published. Required fields are marked *