You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Our application has three models, the ``StudentModel``, the
@@ -246,7 +246,7 @@ Our application has three models, the ``StudentModel``, the
246
246
Create Your Application Routes
247
247
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
248
248
249
-
Our application has five routes, as shown in the `running application homepage <http://127.0.0.1:8000/docs>`__:
249
+
Our application has five routes:
250
250
251
251
.. list-table::
252
252
:header-rows: 1
@@ -286,8 +286,8 @@ Our application has five routes, as shown in the `running application homepage <
286
286
insert the student into our collection, we use the ``inserted_id`` to find
287
287
the correct document and return this in our ``JSONResponse``.
288
288
289
-
FastAPI returns an HTTP ``200`` status code by default; but in this
290
-
instance, a ``201`` created is more appropriate.
289
+
FastAPI returns an HTTP ``200`` status code by default, but we will return a
290
+
``201`` to explicitly that indicate the student has been created.
291
291
292
292
Define the ``create_student`` route using the following code:
293
293
@@ -428,6 +428,12 @@ Our application has five routes, as shown in the `running application homepage <
428
428
429
429
.. step:: Delete Route
430
430
431
+
Because the ``delete_student`` is acting on a single document, we must
432
+
supply an ``id`` in the URL. If we find a matching document and successfully
433
+
delete it, then we return an HTTP status of ``204`` or "No Content." In
434
+
this case, we do not return a document. If we cannot find a student with the
435
+
specified ``id``, then we return a ``404`` error.
436
+
431
437
.. code-block:: python
432
438
433
439
@app.delete("/students/{id}", response_description="Delete a student")
@@ -442,17 +448,14 @@ Our application has five routes, as shown in the `running application homepage <
442
448
443
449
raise HTTPException(status_code=404, detail=f"Student {id} not found")
444
450
445
-
Our final route is ``delete_student``. Because this is acting on a single
446
-
document, we must supply an ``id`` in the URL. If we find a matching
447
-
document and successfully delete it, then we return an HTTP status of
448
-
``204`` or "No Content." In this case, we do not return a document since
449
-
we previously deleted it. However, if we cannot find a student with the specified ``id``, then
450
-
we return a ``404``.
451
+
After you complete these steps, you have a working application that
452
+
uses FastAPI and the {+driver-async+} to connect to your MongoDB deployment, and
453
+
manage student data.
451
454
452
455
More Resources
453
456
--------------
454
457
455
-
For more information, see the following resources:
458
+
For more information about FastAPI integration, see the following resources:
456
459
457
460
- MongoDB's Full Stack FastAPI App Generator:
458
461
- `Blog post: Introducing the Full Stack FastAPI App Generator for Python Developers <https://www.mongodb.com/blog/post/introducing-full-stack-fast-api-app-generator-for-python-developers>`__
0 commit comments