API Integration
The files related to API integrations can be found
in each of the app/app_name/router.py folder(e.g. app/users/router.py). This file contains all the endpoints related to this api, users, which contain all server endpoint(s) related to this app, including get, put, post, etc methods. The
app/app_name/crud.py file contains all of
the crud operations that is being performed on the redis database.
Integrate new API endpoints.
In order to get a new custom endpoint working, you
can follow the below steps: Say you want to add a
new endpoint with the following url
/users/get-profile-image/{user_pk}.
-
First, we have to create a new endpoint for this url
in the
router.pyfile. We will end up with a function like the following:@router.get("/users/get-profile-image/{user_pk}") async def get_profile_image(user_pk: str): try: img = profile_images.get(f"user/{name}/profile.png") return responses.StreamingResponse( img.iter_chunks(), media_type="image/png" ) except Exception as e: return {"status_code": 400, "message": str(e)}
Todo: