Home > other >  How to combine multiple API endpoints?
How to combine multiple API endpoints?

Time:01-04

I joined a project, that already has built all the microservices backends, and they have many API endpoints, something like below:

example1.com/api/a
example2.com/api/b
example3.com/api/c
example4.com/api/d

Recently, the manager of the company asked me to aggregate all the endpoints into one, how can we have just one API endpoint?

Something like below:

example.com/api/a or b or c/*

Is this even possible without help of developers? I mean, no code side changes?

Some of the ideas I have are.

  1. Nginx proxy in front
  2. API GW (but not sure which one suite best for this)

CodePudding user response:

It would require code changes but you could create another microservice which calls the corresponding microservice based on the request.

newMicroservice.com/api/a -> calls example1.com/api/a
newMicroservice.com/api/b -> calls example2.com/api/b
...etc

That way you have a single API endpoint for every microservice.

CodePudding user response:

If you just want to get one endpoint and not to aggregate and merge data in one service, AWS API Gateway will help you. It will be a single entry point for client applications and you can re-route multiple requests on multiple backend services on gateway without changing any code.

You can do some integration on API Gateway:

https://api-gw.example.com/users -> integration request on service: example1.com/api/a

https://api-gw.example.com/orders -> integration request on service: example2.com/api/b

Additionally, you can have single authorization mechanism for these resources on Gateway, like Cognito, AWS_IAM, or Custom Authorization.

If you need to aggregate some API responses, you can use lambdas or BFF Pattern.

  • Related