Better Programming

Advice for programmers.

Follow publication

Member-only story

Client-side Caching of a REST API in Python

Leo van der Meulen
Better Programming
Published in
3 min readApr 6, 2022

Photo by Jan Antonin Kolar on Unsplash

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…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Leo van der Meulen
Leo van der Meulen

Written by Leo van der Meulen

Dutch open data and public transportation enthousiast. Working for over 15 years in public transport. LinkedIn: https://www.linkedin.com/in/leovandermeulen/

Write a response