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
"course": "Experiments, Science, and Fashion in Nanophotonics",
218
220
"gpa": 3.0,
219
-
}
220
-
},
221
-
)
221
+
}
222
+
},
223
+
)
222
224
223
-
StudentCollection Class
224
-
```````````````````````
225
225
226
-
The ``StudentCollection`` class is defined to encapsulate a list of
227
-
``StudentModel`` instances. In theory, the endpoint could return a top-level
228
-
list of ``StudentModel`` objects, but there are some vulnerabilities associated with
229
-
returning JSON responses with top-level lists.
226
+
.. step:: StudentCollection Class
230
227
231
-
Define the ``StudentCollection`` class using the following code:
228
+
The ``StudentCollection`` class is defined to encapsulate a list of
229
+
``StudentModel`` instances. In theory, the endpoint could return a top-level
230
+
list of ``StudentModel`` objects, but there are some vulnerabilities
231
+
associated with returning JSON responses with top-level lists.
232
232
233
-
.. code-block:: python
233
+
Define the ``StudentCollection`` class using the following code:
234
+
235
+
.. code-block:: python
234
236
235
-
class StudentCollection(BaseModel):
236
-
"""
237
-
A container holding a list of `StudentModel` instances.
237
+
class StudentCollection(BaseModel):
238
+
"""
239
+
A container holding a list of `StudentModel` instances.
238
240
239
-
This exists because providing a top-level array in a JSON response can be a `vulnerability <https://haacked.com/archive/2009/06/25/json-hijacking.aspx/>`__
240
-
"""
241
+
This exists because providing a top-level array in a JSON response can be a `vulnerability <https://haacked.com/archive/2009/06/25/json-hijacking.aspx/>`__
242
+
"""
241
243
242
-
students: List[StudentModel]
244
+
students: List[StudentModel]
243
245
244
246
Create Your Application Routes
245
247
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -272,7 +274,7 @@ Our application has five routes, as shown in the `running application homepage <
272
274
.. procedure::
273
275
:style: connected
274
276
275
-
.. step:: Create Your Student Route
277
+
.. step:: Student Routes
276
278
277
279
The ``create_student`` route receives the new student data as a JSON string
278
280
in a ``POST`` request. We must decode this JSON request body into a Python
@@ -312,7 +314,7 @@ Our application has five routes, as shown in the `running application homepage <
312
314
)
313
315
return created_student
314
316
315
-
.. step:: Create Your Read Routes
317
+
.. step:: Read Routes
316
318
317
319
The application has two read routes: one for viewing all students, and one
318
320
for viewing an individual student specified by their ``id``.
@@ -370,7 +372,7 @@ Our application has five routes, as shown in the `running application homepage <
370
372
371
373
raise HTTPException(status_code=404, detail="Student {id} not found")
372
374
373
-
.. step:: Create Your Update Route
375
+
.. step:: Update Route
374
376
375
377
The ``update_student`` route is like a combination of the ``create_student``
376
378
and the ``show_student`` routes. It receives the ``id`` of the student to
@@ -424,7 +426,7 @@ Our application has five routes, as shown in the `running application homepage <
424
426
425
427
raise HTTPException(status_code=404, detail=f"Student {id} not found")
0 commit comments