REST

Representational State Transfer

REST is a paradigma for data transfer between client and server. It’s using the verbs GET, POST, PUT, DELETE (and some others) from the HTTP-protokoll,
hence there is almost everywhere a solid infrastructure. For Machine-2-Machine communication REST is a smart choice.

REST deals with resources uniquely identified by URL’s. For Example: http://test.com/restapi/user/5 could be a user ressource with 5 as an user id. By requesting this resource via different types of HTTP verbs typical CRUD (create, read, update, delete) actions can be performed on the ressource.

I will show some very simple ways how to get startet with REST.

Imagine you would call a REST service with curl from the commandline like this (thats a GET request):

curl 'http://test.com/restapi/user/5'

or with a POST request:

curl --data 'firstname=max&lastname=miller' 'http://test.com/restapi/user/5'

The responding server-side could look somewhat like this.
We deal here with pseude-code. Depending on the framework you use, it differs how to access parameters passed alongside the request.

$method = $_SERVER['REQUEST_METHOD'];
        
switch ($method) {
  case 'GET':
    // fetching the user by the id and return it
       break;
  case 'PUT':
    // create a new user and return it
       break;
  case 'POST':
    // alter a user by its id
       break;
  case 'DELETE':
     // delete the user by its id ...
       break;
}