Geoffrey Nyachae Henry

Create A Simple REST API in PHP? Step By Step Guide!


Lets go

Previously, we learned how to create, read, update and delete database records (CRUD operations) with our PHP, MySQL & OOP CRUD Tutorial.
Today, before we go to JavaScript programming, we will learn how to create a simple REST API in PHP. Enjoy our step-by-step tutorial below!
This post covers the following topics:
1.0 Project Overview
1.1 What is REST API?
1.2 Why do we need REST API?
1.3 Where REST API is used?
1.4 REST API in our tutorials
2.0 File Structure
3.0 Setup the Database
3.1 Create Categories Table
3.2 Dump Data For Categories Table
3.3 Products Table
3.4 Dump Data For Products Table
3.5 Connect to database
4.0 Read Products
4.1 Product Object
4.2 Create “read.php” file
4.3 Add Product “read()” method
4.4 Output
5.0 Create Product

5.1 Create create.php file
5.2 Product create() method
6.0 Read One Product
6.1 Create read_one.php file
6.2 Product readOne() method
6.3 Output
7.0 Update product
7.1 Create “update.php” file
7.2 Product update() method
8.0 Delete Product
8.1 Create “delete.php” file
8.2 Product delete() method
9.0 Search Products
9.1 Create “search.php” file
9.2 Create “search()” method
9.3 Output
10.0 Paginate Products
10.1 Create “read_paging.php” file
10.2 Create “core.php” file
10.3 Create “readPaging()” method
10.4 Create “count()” method
10.5 Get “paging” array
10.6 Output
11.0 Read Categories
11.1 Category object
11.2 Create “read.php” file
11.3 Category “read()” method
11.4 Output
12.0 Download Source Codes
13.0 What’s Next?
14.0 Related Tutorials
15.0 Notes

Before we start, we want to let you know that your feedback is important to us!

If there's a section in this tutorial that is confusing or hard to understand, we consider it as a problem. Please let us know. We will solve this problem within 24 hours.
Send a detailed description of the problem to my email to gnyachae@gmail.com today. Use "codeofaninja.com improvement" as the subject of your email. Thank you!


1.0 PROJECT OVERVIEW

1.1 What is REST API?

To define “REST API”, we have to know what is “REST” and what is “API” first. I’ll do my best to explain it in simple terms because REST has a lot of concepts inside of it that could mean a lot of things.
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. It is usually represented by JSON. This post is worth reading: How I Explained REST to My Wife?
API stands for “Application Programming Interface”. It is a set or rules that allows one piece of software application to talk to another. Those “rules” can include create, read, update and delete operations. If you want to learn more, watch the video below.


Comments