Here we want to create a REST Web Service using PHP on a WAMPServer. The messages will be formatted as JSON entities.
RESTful web services are light weight, highly scalable and maintainable and are very commonly used to create APIs for web based applications.
To start we need to create a new database and a table to store our Users which will have some fields like the FirstName and the LastName. We will do the CRUD operations (Create, Read, Update, Delete).
WAMP or LAMP:
First of all, you should install WAMP, LAMP, or AMPPS. I will use WAMP in this example. WAMP is a PHP server which will allow you do some local tests. WAMP will provide you an Apache server for the Web server side, with MySQL and everything you need.
When WAMP is installed and started and all the services as well, right click on the WAMP icon and start phpMyAdmin to access MySQL.
Create the DB, table, and data:
Create your DB by clicking on the Home icon:
Then click on DataBases and insert the name of your DB:
Now we will create the User table and add some users in it:
Let’s add some users in our new table:
Verify that the data is there:
CREATE TABLE User ( userid CHAR(38) NOT NULL PRIMARY KEY, firstname VARCHAR(30) NOT NULL, lastname VARCHAR(30) NOT NULL )
INSERT INTO User VALUES ( '39D5C3E8-836B-4F86-93AB-B4C51B05CC17', 'John', 'Doe' )
SELECT * FROM User
Create a few more users…
Check my post about how to create the PHP service.