Hello everyone! Lately, I have been researching various techniques for managing APIs as well as routing the backends properly. For all those who are developing applications and would like a good technique for controlling traffic, imposing rate limits and securing endpoints without having to create any middleware themselves, WSO2 API Manager is something worth exploring.
What I intended was to present a brief yet comprehensive explanation on how this works and on how one can establish a proxy.
Why do I need an API Gateway?
If I have a frontend or mobile application that is calling more than one microservice directly, then I will soon be faced with a number of issues:
- API key management becomes an issue.
- Uncontrolled traffic could easily overload my backend infrastructure.
- Usage accounting for various applications becomes harder.
An API gateway sits right in the middle. It handles the authentication and rate limits before a request ever hits your actual services.
Configuring an Initial API Gateway
In case you are testing this locally or configuring your initial project setup, then this is the process that will be involved:
Starting the Publisher: Access the WSO2 API Publisher console.
Create an API: Provide a name for the API (for example, MyTestAPI) and specify a context path (such as /api/v1) and the endpoint URL of your API.
Enabling Security: Enable the API Key or OAuth2 security to ensure that requests which are not authorized are denied access right away.
Setting Up the Rate Limiting: Select any basic plan (for instance, 50 calls per minute).
Trying It Out
After deploying your API to the gateway, you can start testing it out straight from your terminal with curl:
curl -X GET "https://localhost:9443/api/v1/1.0.0/users" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
If all is done properly, then the gateway will verify your access token and forward the request to your backend API service.
Final Thoughts
Having to set up a gateway may seem unnecessary for a small-scale side project, but if your application is multi-service or intended to go into production, having that central gateway is really going to save you some trouble.
If you want to try out WSO2, let me know what you think in the comments below!
Top comments (0)