Skip to content

Commit 04a2be0

Browse files
committed
Update readme
1 parent 10815b6 commit 04a2be0

File tree

1 file changed

+31
-28
lines changed

1 file changed

+31
-28
lines changed

api-gateway/README.md

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,49 +12,53 @@ tags:
1212

1313
## Intent
1414

15-
Aggregate calls to microservices in a single location: the API Gateway. The user makes a single call to the API Gateway,
16-
and the API Gateway then calls each relevant microservice.
15+
Aggregate calls to microservices in a single location, the API Gateway. The user makes a single call
16+
to the API Gateway, and the API Gateway then calls each relevant microservice.
1717

1818
## Explanation
1919

20-
With the Microservices pattern, a client may need data from multiple different microservices. If the client called each
21-
microservice directly, that could contribute to longer load times, since the client would have to make a network request
22-
for each microservice called. Moreover, having the client call each microservice directly ties the client to that
23-
microservice - if the internal implementations of the microservices change (for example, if two microservices are
24-
combined sometime in the future) or if the location (host and port) of a microservice changes, then every client that
20+
With the Microservices pattern, a client may need data from multiple different microservices. If the
21+
client called each microservice directly, that could contribute to longer load times, since the
22+
client would have to make a network request for each microservice called. Moreover, having the
23+
client call each microservice directly ties the client to that microservice - if the internal
24+
implementations of the microservices change (for example, if two microservices are combined sometime
25+
in the future) or if the location (host and port) of a microservice changes, then every client that
2526
makes use of those microservices must be updated.
2627

27-
The intent of the API Gateway pattern is to alleviate some of these issues. In the API Gateway pattern, an additional
28-
entity (the API Gateway) is placed between the client and the microservices. The job of the API Gateway is to aggregate
29-
the calls to the microservices. Rather than the client calling each microservice individually, the client calls the
30-
API Gateway a single time. The API Gateway then calls each of the microservices that the client needs.
28+
The intent of the API Gateway pattern is to alleviate some of these issues. In the API Gateway
29+
pattern, an additional entity (the API Gateway) is placed between the client and the microservices.
30+
The job of the API Gateway is to aggregate the calls to the microservices. Rather than the client
31+
calling each microservice individually, the client calls the API Gateway a single time. The API
32+
Gateway then calls each of the microservices that the client needs.
3133

3234
Real world example
3335

34-
> We are implementing microservices and API Gateway pattern for an e-commerce site. In this system the API Gateway makes
35-
calls to the Image and Price microservices.
36+
> We are implementing microservices and API Gateway pattern for an e-commerce site. In this system
37+
> the API Gateway makes calls to the Image and Price microservices.
3638
3739
In plain words
3840

39-
> For a system implemented using microservices architecture, API Gateway is the single entry point that aggregates the
40-
calls to the individual microservices.
41+
> For a system implemented using microservices architecture, API Gateway is the single entry point
42+
> that aggregates the calls to the individual microservices.
4143
4244
Wikipedia says
4345

44-
> API Gateway is a server that acts as an API front-end, receives API requests, enforces throttling and security
45-
policies, passes requests to the back-end service and then passes the response back to the requester. A gateway often
46-
includes a transformation engine to orchestrate and modify the requests and responses on the fly. A gateway can also
47-
provide functionality such as collecting analytics data and providing caching. The gateway can provide functionality to
48-
support authentication, authorization, security, audit and regulatory compliance.
46+
> API Gateway is a server that acts as an API front-end, receives API requests, enforces throttling
47+
> and security policies, passes requests to the back-end service and then passes the response back
48+
> to the requester. A gateway often includes a transformation engine to orchestrate and modify the
49+
> requests and responses on the fly. A gateway can also provide functionality such as collecting
50+
> analytics data and providing caching. The gateway can provide functionality to support
51+
> authentication, authorization, security, audit and regulatory compliance.
4952
5053
**Programmatic Example**
5154

52-
This implementation shows what the API Gateway pattern could look like for an e-commerce site. The `ApiGateway` makes
53-
calls to the Image and Price microservices using the `ImageClientImpl` and `PriceClientImpl` respectively. Customers
54-
viewing the site on a desktop device can see both price information and an image of a product, so the `ApiGateway` calls
55-
both of the microservices and aggregates the data in the `DesktopProduct` model. However, mobile users only see price
56-
information; they do not see a product image. For mobile users, the `ApiGateway` only retrieves price information, which
57-
it uses to populate the `MobileProduct`.
55+
This implementation shows what the API Gateway pattern could look like for an e-commerce site. The
56+
`ApiGateway` makes calls to the Image and Price microservices using the `ImageClientImpl` and
57+
`PriceClientImpl` respectively. Customers viewing the site on a desktop device can see both price
58+
information and an image of a product, so the `ApiGateway` calls both of the microservices and
59+
aggregates the data in the `DesktopProduct` model. However, mobile users only see price information;
60+
they do not see a product image. For mobile users, the `ApiGateway` only retrieves price
61+
information, which it uses to populate the `MobileProduct`.
5862

5963
Here's the Image microservice implementation.
6064

@@ -64,7 +68,6 @@ public interface ImageClient {
6468
}
6569

6670
public class ImageClientImpl implements ImageClient {
67-
6871
@Override
6972
public String getImagePath() {
7073
var httpClient = HttpClient.newHttpClient();
@@ -114,7 +117,7 @@ public class PriceClientImpl implements PriceClient {
114117
}
115118
```
116119

117-
And here we can see how API Gateway maps the requests to the microservices.
120+
Here we can see how API Gateway maps the requests to the microservices.
118121

119122
```java
120123
public class ApiGateway {

0 commit comments

Comments
 (0)