Browse Source

Improve clarity on path parameter type conversion

pull/15375/head
vikram 3 months ago
parent
commit
82e8c80b8c
  1. 12
      docs/en/docs/tutorial/path-params.md

12
docs/en/docs/tutorial/path-params.md

@ -12,6 +12,18 @@ So, if you run this example and go to [http://127.0.0.1:8000/items/foo](http://1
{"item_id":"foo"} {"item_id":"foo"}
``` ```
/// note
Path parameters are always received as strings from the URL.
Without a type annotation, `item_id` will be treated as a `str`.
By adding a type (e.g. `int`), **FastAPI** will automatically:
- convert the value to the correct type
- validate the input
- return an error if the conversion fails
///
## Path parameters with types { #path-parameters-with-types } ## Path parameters with types { #path-parameters-with-types }
You can declare the type of a path parameter in the function, using standard Python type annotations: You can declare the type of a path parameter in the function, using standard Python type annotations:

Loading…
Cancel
Save