V
V
Valery V.2017-09-24 12:59:33
PHP
Valery V., 2017-09-24 12:59:33

How to make api for microservices in php?

Good afternoon!
The question is in the topic - how to make an api gateway for microservices?
It is not entirely clear to me how the entire chain to the service is arranged: components, purpose, transports, etc. What technologies/stacks are best to use?
The information in Google is somehow written in general, without much detail, so it needs to be "chewed".
Thank you!
Upd: Added a picture.
94efe7c5420b4550977f263c6ded99f2.jpg
Interested in the structure and connections of the block api gateway (highlighted in yellow).

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
Maxim Timofeev, 2017-09-24
@webinar

api is too broad a concept, like a zoo of microservices in php. That's why you can't find information. It's like looking for "do something that will go somewhere, somehow get data from a small program written somehow" It's about nothing. Specify the task. What microservices are we talking about, what is the way to transfer data via api (there are a lot of them, xml, json). And finally, what are you planning to use, since it can be any programming language, this is the essence of api.
If you are trying to find all this, then describe the task itself, for example, "I am making a mobile application, there is such an api that it is better to use."

M
marataziat, 2017-09-24
@marataziat

nginx, haproxy, apache, docker

A
Alexander Kuznetsov, 2017-09-24
@DarkRaven

To put it bluntly, the API in general terms is a set of microservices (hereinafter referred to as MS).
That is, let's say we have an API for getting a list of users, then, in terms of MC, we have an MC "List of Users", the purpose of which follows from the name. The general concept is to have a minimum number of quality actions. Hence its advantages and disadvantages ( https://ru.wikipedia.org/wiki/Microservices ).
In general, in terms of technologies and stacks, it is quite possible in PHP using the same Symfony / Silex / Slim / Equip, etc. Here, on what is convenient, then use it. I have not heard at all that they develop specific solutions for the needs of MS.
If you look at Java, I have seen quite a few examples on spring-boot, on .NET - .net core I think it will be ideal (asp.net core).
JSON is usually chosen as protocols, but no one will scold you if you use protobuf or something else in general. Everyone has their own nuances, in general.
Speaking about general points, usually, next to the MS, they always "use" the same Docker and automatic deployment tools. Those. in fact - MS is often a single block of infrastructure, immediately ready for use after automatic deployment.
UPD. Another extremely important point for the MS is health monitoring. They cannot be neglected. On habrahabr there was not so long ago a whole article about monitoring.
UPD2. Anything can be an aggregator gateway, moreover, it may not be. The simplest gateway option is NGINX, where requests can be proxyed, depending on the requested URL.

M
mitaichik, 2017-09-25
@mitaichik

Considering your comments on other answers, you just need to configure nginx.
It accepts requests from clients, and in accordance with the config, sends them to the right place. Whether it's a different machine, different processes, or multiple php-fpm pools, you can set it up however you like.
Something like

location /match/here1 {
    proxy_pass 127.0.0.1:8081
}

location /match/here2 {
    proxy_pass 127.0.0.1:8082
}

Here, for example, several processes are running that listen on different ports. Different uris lead to the corresponding process that can handle this request. By changing the ip to a remote machine, you can send a request to another machine.
This is just an example, in a real configuration, most likely, you will have to forward headers, and in the case of other machines, provide a secure channel (if required), but in general everything is done very simply. Here is the link devacademy.ru/posts/razbiraemsya-v-http-proksi-ngi...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question