#100DaysOfWeb in Python Transcripts
Chapter: Days 9-12: FastAPI
Lecture: Concept: Passing data to the API

Login or purchase this course to watch this video and the rest of the course contents.
0:00 We saw that if we want to pass data, especially from the query string or part of the URL path
0:05 definition, where we can put variables in there, what we have to do is create the same variables or arguments in our function.
0:12 So here our calculate function now takes an x, y, and a z. Now we're going to specify these to have concrete types.
0:19 So over here, these concrete types that have no default value, these are required. We can also specify an optional integer and set it to be none.
0:28 That way we know for sure that no value was passed for z over here. This value is optional.
0:35 We could pass none or just completely omit it, and it's going to come through with its default value of none.
0:40 But if we do pass some value for z, just like x and y, it has to be a valid integer.
0:46 I don't think we saw that in the example, but if we pass like abc for x, it would say, No, no, no, the type is wrong.
0:52 X has to be an integer, and we can't get an integer out of the string abc.
0:56 So we get this automatically converted to integers, and the types are validated that
1:00 what we pass over are either completely missing, or if they are there, they can be converted
1:05 to the types that we said they should be, including z, which is optional. It either has to be missing or it can be an integer.


Talk Python's Mastodon Michael Kennedy's Mastodon