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,
0:01 especially from the query string or part of the URL path definition,
0:05 where we can put variables in there,
0:06 what we have to do is create the same variables, or arguments, in our function.
0:11 So here our calculate function now takes an X,
0:13 Y and Z. Now we're going to specify these to have concrete types.
0:18 So over here, these concrete types that have no default value these are required.
0:23 We can also specify an optional integer and set it to be none. That way,
0:27 we know for sure that no value was passed for Z over here.
0:32 This value is optional, we could pass none or just completely omit it,
0:37 and it's going to come through with its default value of none.
0:39 But if we do pass some value for Z, just like X and Y,
0:43 it has to be a valid integer.
0:45 I don't think we saw that in the example, but if we had passed like ABC for
0:48 X it would say "No, no,
0:49 no, the type is wrong".
0:51 X has to be an integer
0:52 and we can't get an integer out of the string
0:54 ABC. So we get this automatically converted to integers,
0:58 and the types are validated that what we pass over are either completely missing or if
1:03 they are there, they could be converted to the types that we said they should
1:06 be, including Z, which is optional.
1:07 It either has to be missing or it can be an integer.