Coding an expess gateway policy plugin 12 Sep 2017
Hello everyone,
I was looking at a efficient way to build an API gateway for my job. So first if you have no idea of what I am talking about here are some good articles about it and micro-services architectures.
- API gateway pattern
- Building Microservices: Using an API Gateway
- Embracing the Differences : Inside the Netflix API Redesign
- Martin Fowler serverless
I know that nginx is probably an excellent option but the licensing does not really suit us and we were looking for an open-source and free option. I also need to have a look at kong.
I discovered express-gateway and I gave it a try.
express-gateway
You can find all the details inside the github repo. I managed pretty easily to code my own specific policy inside the gateway that does the following :
- Call http://api.chucknorris.io/jokes/random using superagent
- Extract the value field of the response body to get the quote (warning some of them can be offensive, I am not responsible for this API)
- Call http://numbersapi.com/{number} passing the length of the first quote as the number path param
- Extract the text field of the response body
- Return javascript object with the 2 quotes to caller, does not call next(), with following format
{chuckQuote : quote1, numberQuote: quote2}
Even if the gateway is still very young I think it is an intesting project to follow !