Member-only story
Client-side Caching of a REST API in Python
A simple cache for caching REST API responses on the client side. This reduces the network load and API calls and increases performance
We are living in an API enabled world. More and more applications are built on top (open) apis. Sometimes calling the same API, the same endpoint with the same parameters frequently, resulting in the same response.
Performing a search on client-side caching did not result in a nice solution fitting my usage so I decided to build my, very simple, own. In this example, it caches JSON results from REST apis. But the JSON part is optional.
The cache is built in a python function that performs a web call and translates the resulting JSON content to a dictionary. This function is used when a REST call is required somewhere in the code.
The json_api_call
performs an HTTPS request to the specified host and base url. The params
parameter must contain the URL-encoded parameters, e.g…