YASE - Yet Another Software Engineer
The most common practice, often seen in FastAPI’s official documentation, is to use a verb_resource
or action_resource
pattern, where:
verb
/ action
: Describes the operation performed by the route, often aligned with CRUD verbs (Create, Read, Update, Delete) or specific actions.
read_
: for GET
operations (reading one or more items).create_
: for POST
operations (creating a new item).update_
: for PUT
or PATCH
operations (updating an existing item).delete_
(or remove_
): for DELETE
operations (deleting an item).search_
, upload_
, login_
, process_
).resource
: describes the entity or resource the route operates on (generally singular for operations on a single item, plural for operations on collections).
item
, items
user
, users
order
, orders
product
, products
Practical Examples:
GET /items/
: reads a collection of items.
read_items
GET /items/{item_id}
: reads a single specific item.
read_item
POST /items/
: creates a new item.
create_item
PUT /items/{item_id}
: completely updates an item.
update_item
PATCH /items/{item_id}
: partially updates an item.
patch_item
(or sometimes update_item
is also used for PATCH)DELETE /items/{item_id}
: deletes an item.
delete_item
POST /users/{user_id}/avatar
: uploads an avatar for a specific user.
upload_user_avatar
POST /token
: generates an access token (login).
login_for_access_token
or create_access_token
GET /products/search
: searches for products.
search_products
Additional rules and good practices:
snake_case
(lowercase words separated by underscores) for function names.def read_item(...)
, it should be obvious that it handles a request to read a single item.handle_request
, process_data
, or endpoint1
are too generic and should be avoided.In conclusion: the “rule” to follow is the verb_action_resource
convention in snake_case
, applied with consistency, because it maximizes the readability and maintainability of your FastAPI code.