Summary
NotesUsing APIs to provide the logic for rendering web views is an excellent way to build web applications that are more efficient, scalable, and maintainable. By separating the frontend and backend logic into distinct components, developers can create a more flexible architecture that can adapt to changing needs over time. Using APIs also allows developers to reuse existing code across multiple applications or platforms, saving time and resources in the development process. Additionally, using APIs provides a more secure way to transmit data between the frontend and backend, as it minimizes the amount of sensitive information that is exposed to potential attackers.
Even though this example project is accessing the API function directly, ultimately, using APIs to provide the logic for rendering web views enables developers to build more robust, secure, and scalable web applications that meet the needs of modern users.
Testing the web pages#
The example code includes test_web_views.py, which tests the pages the same way as the APIs: creating posts through the form with an uploaded image, checking the image was renamed and cropped, that Markdown is rendered and scripts are removed, updating, deleting and the 404 page. The in-memory database fixture moved from test_blog_apis.py into conftest.py, where pytest shares it with every test file, and it also sends uploads to a temporary directory.
The example code at this point is tagged ch04-web-pages in the example repository. To get it:
git clone https://github.com/codewalkr/fastapi-example-for-you.git
cd fastapi-example-for-you
git checkout ch04-web-pages