📝 Update code examples in docs
Hi! I did some improvements for code exmples;
- Renamed function because it is
putendpoint and logicaly it should beupdatenotcreate; - ~Removed redundant
ifstatement becauseqparam in those examples are required. Or I can addNoneto annotations;~
📝 Docs preview for commit c9d3b22107983740f9590e5c1f25592e10a13481 at: https://63ccee9f0fb8da5c9c02fac2--fastapi.netlify.app
📝 Docs preview for commit dc6946f220f1e475c471462bcd1d1fee38491cb8 at: https://63ccf0f8cf78ab6745a882e4--fastapi.netlify.app
I understand the suggestion for "2", however I suggest not making those changes because that code is repeated in multiple places throughout the tutorials. As I understand the tutorials, they build on each other somewhat, and they focus on specific items in each section. It seems to me that making these changes in a few places adds inconsistencies that the learner has to investigate as they change. It may be more useful to keep it consistent even if the example isn't optimal?
@Ryandaydev First time when learner see this q parameter in this article https://fastapi.tiangolo.com/tutorial/query-params/#optional-parameters . And here it looks logical because q is optional and code example has if condition for that parameter. For consisten I suggest add None for q param inside annotations. After this if statement make sense. And it will look like previous examples with q param:
@app.get("/items/{item_id}")
async def read_items(q: str | None, item_id: int = Path(title="The ID of the item to get")):
results = {"item_id": item_id}
if q:
results.update({"q": q})
return results
📝 Docs preview for commit 2bfa4588102e298c1cac848546993a003c33b78d at: https://64697a4de93dbc10f72678bd--fastapi.netlify.app
Ok. I removed controversial changes and left only renamed functions
Nice, makes sense, thank you @OttoAndrey! 🍰
And thanks everyone for the input! ☕