Modern APIs with FastAPI and Python Transcripts
Chapter: Building our first API
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 definition, where we can put variables in there,
0:07 what we have to do is create the same variables, or arguments, in our function. So here our calculate function now takes an X,
0:14 Y and Z. Now we're going to specify these to have concrete types. So over here, these concrete types that have no default value these are required.
0:24 We can also specify an optional integer and set it to be none. That way, we know for sure that no value was passed for Z over here.
0:33 This value is optional, 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 had passed like ABC for X it would say "No, no, no, the type is wrong". X has to be an integer
0:53 and we can't get an integer out of the string ABC. So we get this automatically converted to integers,
0:59 and the types are validated that what we pass over are either completely missing or if
1:04 they are there, they could be converted to the types that we said they should be, including Z, which is optional.
1:08 It either has to be missing or it can be an integer.

Talk Python's Mastodon Michael Kennedy's Mastodon