The Secrets of API Automation
API Automation is something very few people know about or implement but just about EVERY enterprise uses . It enables them to quickly:
- automatically tie webhooks to any endpoint
- batch process any api without making code changes
- chain api calls without code changes (or hard coding the chains)
- separate out processes (batching, chaining, webhooks calls are handled by separate servers so as not to interfere with normal calls)
- avoid unnecessary redirects ( vs forwards : see difference between forward and redirect)
Through this, they are able to greatly increase their speed, scale and development time while decreasing their code base by 30–50%. I know because I have helped Netflix, VMWare, Paypal and others with this.
Abstracting the Communication Layer
One of the first issues with doing API automation is that you have to abstract the communication layer from the business logic.
The original API Pattern was written in the 1970’s for centralized architectures and was NEVER intended for distributed architectures as it binds communication logic to the business logic so it cannot be shared with architectural instances.
You can see that in GraphQL schema stitching as each api call has to issue a separate request/response to each endpoint to ‘stitch’ all endpoints together. The call flow looks something like this:
To fix this, we abstract that logic away so we can start sharing the request/response to something more like this:
Notice how aside from having NO REDIRECT, we now have the IO LOGIC separated from the BIZ LOGIC in the ‘API Application’
This is because we abstracted the logic to what is commonly referred to as an ‘Interceptor’. Some examples of this pattern:
- Java Spring Framework calls it a ‘HandlerInterceptorAdapter’
- Node.js Loopback calls it a ‘Sequence’
- Angular calls it an ‘Interceptor’
Using the ‘Interceptor Pattern’ , we can intercept the request/response prior to handoff to the controller and post-processing from the controller. And should we need to, we can hand-off from the postInterceptor to the preInterceptor creating a loop for automation.
Are There Working Examples?
One framework that stands out as a working example of API Automation is the Open Source BeAPI API Framework. This framework has been used by enterprises and small businesses alike to automate their backends and simplify their implementations.
Rather than writing code that looks like this:
… you can write code that looks like this…
Far less code to write because the communication logic has been abstracted away from your business logic and been automated.
And because it has been automated, there is less to test and nothing to screw up.
Automated API’s are the Future
There is no reason why your developers should be writing, testing and changing api’s anymore when all this can be automated. After all, if the big boys can do it and an open source project is available for you to do it, what is stopping you?
If you enjoyed this story, you may also enjoy additional reading about API’s and software development below: