1.1.0 Create the Notification Feature
0. Learning Materials
Andrew's repo: week-1-react-flask-coding
Task List
1. Workflow
In this episode, we are creating a new endpoint in the backend and the corresponding page in the frontend. We configure both the backend and frontend accordingly so that the frontend page displays the data grabbed from the backend when the corresponding backend API is called.
1.1 OpenAPI
Add the OpenAPI extension in VS code.
An
openapi.yml
file will be automatically generated. This file should be at the root of our Cruddur project.The complete code is found here.
1.2 Backend: Create Notifications endpoint
Line 2: add the
import
statement so the flask serverapp.py
knows where to grab theNotifications
data when user requests hit the endpoint (/api/activites/notifications
). At this stage, our data are hard-coded mock data.Block 5-8: the function defines the process of fetching Notifications data.
The
NotificationsActivities
class defined in the Python fileservices.notifications_activities
will actually fetch and handle the data.
Create
notifications_activities.py
file in theservices
folder.At the moment, we copy everything from
home_activities.py
. The complete code is found here:
1.3 Frontend
Now, let's create a skeleton of the Notifications page in the frontend.
As we created the endpoint for Notifications in the backend, we have to create the frontend page for it. Create a path for notifications and map it to a new page called NotificationsFeedPage
.
Then create the following files at frontend-react-js/src/pages
:
NotificationsFeedPage.js
NotificationsFeedPage.css
Copy everything from HomeFeedPage
js and css files respectively. Replace home
with notifications
(the code is here).
Both the frontend and backend is ready. Run docker compose and see if the Notifications page works.
Test your backend endpoint too. See how each object's attributes are mapped to the elements in the page in the frontend.
Last updated