PHP Microservices — Creating A Basic Restful Crud API
Published in
4 min readJan 2, 2019
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:
- Non-blocking I/O for the client when implemented in languages like Javascript
- Easy to manage resources, meaning its easy to organize and group calls together.
- The syntax is easy to follow because it follows HTTP standards
- The endpoints are stateless, aka idempotent. This reduces the side effects of unexpected outputs occurring.
- 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…