The import path section doesn't work anymore with the None default. On line 18, leave out "NONE". def student(student_id: int = Path(description="input the Id of the student"))
The import path section doesn't work anymore with the None default. On line 18, leave out "NONE". Use following: def student(student_id: int = Path(..., description="input the Id of the student"))
@@ajayr1402 it was updated by now. for the next example you also don't need to import typing anymore from Python 3.9 onwards, instead you can write it like this: def get_student(name: str | None = None):
In create-student method, we should convert Student object to dictionary object because Student object does not support item assignment now: students[student_id] = student.dict()
For update, instead of writing a bunch of if statements, the following should work: `students[student_id] = students[student_id].copy(update={k: v for k, v in source.dict().items() if v is not None})`
You are being watched and your behavior is constantly trying to be predicted by various malicious actors, who are willing to invade your privacy in every way for the chance of marginal profit increase. RUN.
I didn't understand the real difference between app.post, put and delete. If i run the functions under app.put and app.delete decorators in the given example with app.post, still it is working without any error.
Great video, thanks. I am curious if there exists some conventions for the Error objects we return from time to time. When I want to analyse the output with JS it would get messy I guess if it doesn't follow any convention. Or maybe one could send an appropiate HTTPErrorCode (like 500 when internal server error is thrown)?
This is beautifullll...tnx. Which server solution do you recommend for a baby-startup, no big data requests, or ML type of service, but will serve to specific region (as opposed to globally)
this was the amazing video on FastAPI and it really helped me to gain the fundamental knowledge about it. Just one query why FastAPI and not the old school proven methods like Django or Flask?
24:41 it gives an error: "Path parameters cannot have a default value" . I solved it by changing the code to: def get_student(student_id:int = Path(description="The ID of the student you want to view")):
@56:15. The value is giving error while updating student object students[student_id].name = student.name AttributeError: 'dict' object has no attribute 'name' I solved it by using it like this. students[student_id]["name"] = student.name In python, dictionary values cant be acessed like dict.key = new_value. It can be accessed like dict[key] Reply....
More beautiful version in my opinion (less reps; better for requests with many parameters) student_dict = student.__dict__ for param in student_dict.keys(): if student_dict[param] != None: students[student_id][param] = student_dict[param] Explanation: "student" is an instance of class . as an instance it has a built-in method called "__dict__". Method returns a dict of namespaces. now we can have this dict in "varstudent_dict" then we run through its keys ("param" stores key every iteration) And we universally check None in request key list
Hello FreeCodeCamp. You videos helped me so much and there is question. Are there coming Redux Course? I cant find a new actual course for redux on youtube that was loaded in less than a year. Anyways, you made my career.
Quick Question - Regarding Put Method For this example it was fine to write code for 3 column but if DB contains 100 column then do we need to write if statement for all 100 column or is there any better way to handle this situation?
You can iterate over every single object property and just get the ones that are not None. Refer to Stack Overflow Question: "Iterate over object attributes in python" However, FastAPI documentation (Body - Updates section) suggests that: - If you can, use PATCH instead of PUT for partial updates (though this is NOT required) - Use Pydantic's exclude_unset parameter and/or update parameter
I built an api using fastapi and deployed to heroku. But when I tried to fetch something from that api using javascript fetch method, I'm encountering something know as CORS error But the fast api docs said that we can resolve that error using CORS middleware from fastapi and select particular origins for fetching. But the selected origins is not working when I tried that method. It's working if I give * as origins. How do I solve this?
Have the people who praise this video actually done the tutorial? Most of this stuff is deprecated or doesnt even work to begin with even if you use the exact same code. The instructor is hard to understand for non native speakers and he makes multiple errors during the video so he clearly didnt even prepare properly. I had to use Chat GPT in the end to fix his code
The import path section doesn't work anymore with the None default. On line 18, leave out "NONE". def student(student_id: int = Path(description="input the Id of the student"))
OMG thanks!!!
😃 when i put None like this Path(None) i got this response "Path parameters cannot have a default value"
thanks
Thanks! Same thing happened to me, has to type ... instead of none
Does that work on 33 40 when we make student :str==None?
Thanks! I was exactly stuck here.
The import path section doesn't work anymore with the None default.
On line 18, leave out "NONE".
Use following:
def student(student_id: int = Path(..., description="input the Id of the student"))
Why does it happens acctually ?
@@ajayr1402 it was updated by now. for the next example you also don't need to import typing anymore from Python 3.9 onwards, instead you can write it like this:
def get_student(name: str | None = None):
@@Fussfackel Yes. This can achieved by using Query=(None, Description=........) as well. Just QUERY instead of PATH.
Was waiting for a FastAPI course and boom !! 🔥
In create-student method, we should convert Student object to dictionary object because Student object does not support item assignment now:
students[student_id] = student.dict()
can u explain
Great explanation and demo for beginners. Straightforward and cut-to-cut. Thanks.
Great tutorial for the one who knows python and is new to FastApi. Thanks for this one and hope to see more informative videos like this.
great video, and yes, you should update the Path model default value input type in the video
Really simple and easy to understand Tutorial for FastAPI!
the docs feature is awesome. Thanks for this video, straight to the point on APIs
For update, instead of writing a bunch of if statements, the following should work:
`students[student_id] = students[student_id].copy(update={k: v for k, v in source.dict().items() if v is not None})`
Short and easy to the point video to do quick start with FastAPI.. Thanks for content
>get out of shower
>need to learn fastapi
>this
i swear to god i'm being watched.
You are being watched and your behavior is constantly trying to be predicted by various malicious actors, who are willing to invade your privacy in every way for the chance of marginal profit increase. RUN.
Thank you so much for the energy and the application you put in sir. You just answered all my questions.
When you typed "/docs" and it showed the documentation... I am like 🤯
Can not take any default parameters in path, why it is happening?
Congrats for 4 Million. However this channel deserver 40 million.
Couldn't agree more! +1
Please Make More Than 10+ hours FAST-API Details course.Community needs this.TH-cam has not much content about fastapi.Because it is new tech.
can Path have default parameter, I tried but got error. in time stamp 24.02 you have used it
Easy way to teach beginners, Thanks sir
Is there an advance course ?!
Thank you Tomi and freeCodeCamp
Thank you Tomi and frecodecamp. Excelent material. Happy coding!!
Nice tutorial!
Thank you for you excellent tutorial, it's easier than django rest, Egypt
Wow what a video. Worth one hour...
Wow i particularly liked this /docs thing, very useful, thanks for this video.
I didn't understand the real difference between app.post, put and delete. If i run the functions under app.put and app.delete decorators in the given example with app.post, still it is working without any error.
Verry good tutorial! It's showing how to create swagger/openapi in depth!
Thank you!
Man, that was exactly what I was looking for. Thank you very much for such a video. Keep up the good work!
Love it but need a complete advanced fastapi course!
Great video, thanks. I am curious if there exists some conventions for the Error objects we return from time to time. When I want to analyse the output with JS it would get messy I guess if it doesn't follow any convention. Or maybe one could send an appropiate HTTPErrorCode (like 500 when internal server error is thrown)?
We really Need a Fastapi graphql subscriptions tutorial!!!
Thank you! This video explains it so clear, that I finally understand how to use it : )
i have this problem: 'uvicorn' is not recognized as an internal or external command,
operable program or batch file.
Hey! Can you make a video on haskell and fp?
It was great to startup with (y) , any video for postgresql along with fastapi?
Nice course, but where isy cheat sheet?
Thank you for this video. it is easy for the beginner to understand step by step.
That /docs seems so handy!
This is beautifullll...tnx. Which server solution do you recommend for a baby-startup, no big data requests, or ML type of service, but will serve to specific region (as opposed to globally)
import path section doesn't work anymore with the None default use "..." instead of "None"
How to solve CORS problems in FastAPI? I followed official docs but it did not work.
this was the amazing video on FastAPI and it really helped me to gain the fundamental knowledge about it. Just one query why FastAPI and not the old school proven methods like Django or Flask?
Awesome video, thank you soo much!
watching this video was worth it 💗
please bring Angular full course....
At 37:05 the server was not responding because you were highlighting the command prompt.
You can't publish videos with errors in code. Please check the courses before publishing.
24:41 it gives an error: "Path parameters cannot have a default value" . I solved it by changing the code to:
def get_student(student_id:int = Path(description="The ID of the student you want to view")):
@56:15. The value is giving error while updating student object
students[student_id].name = student.name
AttributeError: 'dict' object has no attribute 'name'
I solved it by using it like this.
students[student_id]["name"] = student.name
In python, dictionary values cant be acessed like dict.key = new_value. It can be accessed like dict[key]
Reply....
More beautiful version in my opinion (less reps; better for requests with many parameters)
student_dict = student.__dict__
for param in student_dict.keys():
if student_dict[param] != None:
students[student_id][param] = student_dict[param]
Explanation:
"student" is an instance of class .
as an instance it has a built-in method called "__dict__".
Method returns a dict of namespaces.
now we can have this dict in "varstudent_dict"
then we run through its keys ("param" stores key every iteration)
And we universally check None in request key list
how do use FastAPI for an image recognition model created using pytorch?
Looking forward to a full course on FastAPI
Hello FreeCodeCamp. You videos helped me so much and there is question. Are there coming Redux Course? I cant find a new actual course for redux on youtube that was loaded in less than a year. Anyways, you made my career.
Thanks for the vid. Very to the point.
i was waiting for this course, thanks a lot
This was an awesome intro to FastAPI!
Need one for FastAPI with SQLAlchemy and mysql DB
You should have given credit to Tech with Tim cos this video is a complete replica of his video on same topic
jesus this is fast, didn't need to spend 32 hours to learn django syntax lol
Very nice tuto !!! Kudos
I've developed an edu-Commerce Web app with FastApi 😎
please provide your github link about your project.
@ 59:00
why "/get-by-name /{student_id}" is giving Internal server error ?
Thanks a lot for sharing this video. I learned a lot
@50:19 there's the patch method for partial updates...
Great framework!
Nice tutorial. Is there a way to test app with python code?
How we can get all info after the post method ???
Excellent content, thanks!
For 55:40 - dictionaries have an update() method
Cool! Is this course available in the site?
Wait a minut, python is fast now or what?
Thanks you bro, your video interesting
This is exactly a copy paste from Bek Brace original FastAPI crash course !
Exactly!
i saw it last week and it's a great one, but they are not quite similar, this will be unfair to Bek's tutorial
Awesome Content
Thank you for this video
how python can be fast?
Excellent course!
Quick Question - Regarding Put Method
For this example it was fine to write code for 3 column but if DB contains 100 column then do we need to write if statement for all 100 column or is there any better way to handle this situation?
You can iterate over every single object property and just get the ones that are not None.
Refer to Stack Overflow Question: "Iterate over object attributes in python"
However, FastAPI documentation (Body - Updates section) suggests that:
- If you can, use PATCH instead of PUT for partial updates (though this is NOT required)
- Use Pydantic's exclude_unset parameter and/or update parameter
Thanks 🙏🥰
This is very good!
thank you so much..
Need FastApi cheat shheet
Thank you!
Awesome explanation
Love u freecodecamp❤️❤️❤️
amazing !!!
Not such helpful not working
I built an api using fastapi and deployed to heroku.
But when I tried to fetch something from that api using javascript fetch method, I'm encountering something know as CORS error
But the fast api docs said that we can resolve that error using CORS middleware from fastapi and select particular origins for fetching.
But the selected origins is not working when I tried that method.
It's working if I give * as origins.
How do I solve this?
Your origin should be the heroku instance IP. The reason * works is because it's a wildcard and will accept any IP as an origin.
Wrap in it CORS. Search for enabling cors in fast api. I did the same with my flask api
Which text theme is being used for vs code ?
night owl
Thanks Tomi
thanks a lot Brother :)
24:40 Error Solution: def get_student(student_id: int = Path(..., description="Enter the ID of the student you want to view.", gt=0)):
Have the people who praise this video actually done the tutorial? Most of this stuff is deprecated or doesnt even work to begin with even if you use the exact same code. The instructor is hard to understand for non native speakers and he makes multiple errors during the video so he clearly didnt even prepare properly. I had to use Chat GPT in the end to fix his code
Thank you so helpful
Thank you so much, but please try to get better in
English to be more understandable for us. All respect and love
Excellent
THAKKS MAN
Sir hindi tutorial banaye samjh nhi a kuch
Which theme are you using for VS Code? Thanks.
Night owl
Tommy sounds like a Nigerian