asacristani / fastapi-rocket-boilerplate

🐍💨 FastAPI Rocket Boilerplate to build an API based in Python with its most modern technologies!
MIT License
464 stars 65 forks source link

Extends the NoCacheMiddleware to allow custom caching headers on a per-route basis #11

Closed Adesoji1 closed 1 year ago

Adesoji1 commented 1 year ago

Description

This pull request extends the NoCacheMiddleware to allow custom caching headers on a per-route basis. It introduces the ExtendedNoCacheMiddleware class, which merges custom caching headers specified in the request scope with default no-cache headers.

Motivation

Previously, caching headers were set globally for all routes. With this enhancement, developers can have fine-grained control over caching behavior.

Testing

To test the changes, I have added unit tests to ensure that the middleware functions correctly. I have also updated the main application to use the ExtendedNoCacheMiddleware for a specific route.

Known Limitations

Fixes #https://github.com/AdrianPayne/fastapi-rocket-boilerplate/issues/10

This pull request resolves the issue #https://github.com/AdrianPayne/fastapi-rocket-boilerplate/issues/10 where custom caching headers were not supported on a per-route basis.

In addition i also added a requirements.txt file using pipreqs python library. my python version is 3.8 and also created the main.py located at app/core/middleware/main.py Screenshot from 2023-10-10 10-40-12 to show you how to use. the screenshot is attached for you to view the cached route.

asacristani commented 1 year ago

Hello Adesoji,

The nocache middleware is a middleware oriented to avoid the cache in the swagger documentation (a common situation working with Fastapi). Therefore, the enhancement of this PR is not needed now. Also, there are some points to fix:

  1. we are using Poetry for requirements, please follow the README.md for installing libraries.
  2. the solution is not passing the unit-testing and style checks.
  3. I do not think it is convenient to create a new Fastapi app inside of the middleware folder.

Thanks so much for your time and effort on this, please keep using the project and supporting like this!

Adesoji1 commented 1 year ago

So @AdrianPayne what feature do you want implemented ? 🥺

asacristani commented 1 year ago

A good start step could be to cover all the code with unit testing (only 4% is missing). Does this sound good to you?