PHP Microservices — Creating A Basic Restful Crud API

Devin Dixon
Helium MVC

--

This tutorial is part of a series of creating Microservices with PHP. Part 1 discussed Sockets, Part 2 discussed RabbitMQ.

One of the most prominent ways to create access to a microservice today is through a RESTful API. REST has great advantages over other protocols like sockets that include:

  1. Non-blocking I/O for the client when implemented in languages like Javascript
  2. Easy to manage resources, meaning its easy to organize and group calls together.
  3. The syntax is easy to follow because it follows HTTP standards
  4. The endpoints are stateless, aka idempotent. This reduces the side effects of unexpected outputs occurring.
  5. Easy to implement CRUD operations — Create, Read, Update, Delete.

Restful over HTTP normally breaks down into 4 types of requests of GET, POST, PUT and DELETE. There are other request types that are outside of the scope of this article. The requests can be described as:

  • GET: Normally maps to an operation of retrieving data. In CRUD, this is your READ.
  • POST: Used for creating data, or in CRUD the CREATE.
  • PUT: Called when a user wants to update data. Is the U in CRUD.
  • DELETE: Used to remove…

--

--