Book Image

PHP Microservices

By : Pablo Solar Vilariño, Carlos Pérez Sánchez
Book Image

PHP Microservices

By: Pablo Solar Vilariño, Carlos Pérez Sánchez

Overview of this book

The world is moving away from bulky, unreliable, and high-maintenance PHP applications, to small, easy-to-maintain and highly available microservices and the pressing need is for PHP developers to understand the criticalities in building effective microservices that scale at large. This book will be a reliable resource, and one that will help you to develop your skills and teach you techniques for building reliable microservices in PHP. The book begins with an introduction to the world of microservices, and quickly shows you how to set up a development environment and build a basic platform using Docker and Vagrant. You will then get into the different design aspects to be considered while building microservices in your favorite framework and you will explore topics such as testing, securing, and deploying microservices. You will also understand how to migrate a monolithic application to the microservice architecture while keeping scalability and best practices in mind. Furthermore you will get into a few important DevOps techniques that will help you progress on to more complex domains such as native cloud development, as well as some interesting design patterns. By the end of this book you will be able to develop applications based on microservices in an organized and efficient way. You will also gain the knowledge to transform any monolithic applications into microservices.
Table of Contents (19 chapters)
PHP Microservices
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Implementing a microservice call


Now that we know how to make a call, let's create a more complex example. We will build our battle system. As mentioned in the previous chapters, a battle is a fight between two players in order to get secrets from the loser. Our battle system will consist of three rounds, and in each round, there will be a dice throw; the user that wins the most rounds will be the winner and will get a secret from the loser's wallet.

Tip

We suggest using some testing development practices (TDD, BDD, or ATDD) as we explained before; you can see some examples in the preceding chapter. We will not include more tests in this chapter.

In the Battle microservice, we can create a function for the battle in the BattleController.php file; let's look at a valid structure method:

    public function duel(Request $request) 
    {
        return response()->json([]);
    }

Do not forget to add the endpoint on the routes.php file to link the URI to our method:

    $app-&gt...