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, itemsuser, usersorder, ordersproduct, productsPractical Examples:
GET /items/: reads a collection of items.
read_itemsGET /items/{item_id}: reads a single specific item.
read_itemPOST /items/: creates a new item.
create_itemPUT /items/{item_id}: completely updates an item.
update_itemPATCH /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_itemPOST /users/{user_id}/avatar: uploads an avatar for a specific user.
upload_user_avatarPOST /token: generates an access token (login).
login_for_access_token or create_access_tokenGET /products/search: searches for products.
search_productsAdditional 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.