From 4f8d2dd04597cd7aceda0f7723568e6c5015bd40 Mon Sep 17 00:00:00 2001 From: xnought Date: Thu, 2 May 2024 16:21:27 -0700 Subject: [PATCH] response model --- docs/overview.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/overview.md b/docs/overview.md index b288b84..d497915 100644 --- a/docs/overview.md +++ b/docs/overview.md @@ -52,9 +52,14 @@ The FastAPI [`backend`](../backend/) has all its definitions in the [`backend/sr You can easily then define HTTP endpoints like so ```python -@router.get("/test/overview") +class TestOverviewResponse(CamelModel): + hello_there: str + +@router.get("/test/overview", response_model=TestOverviewResponse) def test_overview(): - return {"hello": 1} + return TestOverviewResponse(hello_there="world") ``` -would trigger if a `GET` request to the backend at route `test/overview` was received and would respond with the JSON of `{"hello": 1}`. Please see examples in the [`backend/src/api/protein.py`](../backend/src/api/protein.py). +would trigger if a `GET` request to the backend at route `test/overview` was received and would respond with the JSON of `{"helloThere": "world"}`. As you can see `TestOverviewResponse` object is transformed in JSON on the response and the variables are switched from snake_case to camelCase. + +Please see examples in the [`backend/src/api/protein.py`](../backend/src/api/protein.py). \ No newline at end of file