Path Parameters in FastAPI

Learn about path parameters and automatic parsing of path parameters.

Introduction to path parameters

Path parameters help to call an API specifically to a particular resource or route. As we’ll specifically route to a particular resource, we don’t need to build a body that will be sent with the request to find a particular resource which reduces the execution time of the request.

Path parameters are surrounded by curly brackets and help the developers to control the representation of a particular resource in your application.

A path parameter is a string that appears before a query string and is within the path of an end-point. It provides an efficient way to parameterize a resource.

In FastAPI, we can declare path parameters with the same syntax used by Python format strings. Let’s look at the code below to see this concept in action.

Get hands-on with 1400+ tech skills courses.