July 2019
Intermediate to advanced
502 pages
14h
English
The main job of the API gateway service is to implement the API gateway pattern we discussed in Chapter 2, Getting Started with Microservices. For example, here is how it routes the get links requests to the proper method of the link microservice.
The Link class is derived from the Resource base class. It gets the host and port from the environment and constructs the base URL.
The get() method is called when a GET request for the links endpoint comes in. It extracts the username from the GitHub token in the _get_user() function and parses the query part of the request URL for the other parameter. Then, it makes its own request to the link manager service:
class Link(Resource): host = os.environ.get('LINK_MANAGER_SERVICE_HOST', ...