Introduction
URLs should describe things, not actions. This makes them easier to understand and use.
URLs should describe things, not actions. This makes them easier to understand and use.
/resources
/resources/{id}Use nouns (things) in URLs, not verbs (actions).
Use HTTP methods like GET, POST, PUT, DELETE to express actions.
users resource.GET /users POST /users GET /users/123 PUT /users/123 DELETE /users/123
orders resource and specific order by ID./orders
/orders/456get, create, or delete in URLs.Avoid: /getUser Avoid: /createOrder Avoid: /deleteProduct
This simple API uses URLs with nouns only. Actions are done by HTTP methods like GET and POST.
from flask import Flask, jsonify, request app = Flask(__name__) users = {"1": {"name": "Alice"}, "2": {"name": "Bob"}} @app.route('/users', methods=['GET']) def list_users(): return jsonify(users) @app.route('/users/<user_id>', methods=['GET']) def get_user(user_id): user = users.get(user_id) if user: return jsonify(user) return jsonify({"error": "User not found"}), 404 @app.route('/users', methods=['POST']) def create_user(): data = request.json new_id = str(len(users) + 1) users[new_id] = {"name": data.get('name', 'Unknown')} return jsonify({"id": new_id}), 201 if __name__ == '__main__': app.run(debug=True)
HTTP methods tell what action to do, so URLs stay clean and simple.
Using nouns in URLs helps everyone understand what the URL points to.
Keep URLs consistent and predictable for easier API use.
Use nouns, not verbs, in URLs to name resources.
Use HTTP methods (GET, POST, PUT, DELETE) to express actions.
This makes APIs easier to understand and maintain.
/users/123 represent a user resource with ID 123./getUser/123, /createUser, and /deleteUser/123 contain verbs (get, create, delete), which is against best practice./users/123 -> Option D/users/123 [OK]/orders/456 to update an existing order?/orders/456, the correct HTTP method is PUT.DELETE /products/789, what is the expected action?/products/789 identifies product 789, so DELETE removes it.POST /updateUser/123/updateUser/123 contains the verb 'update', which violates REST best practices./posts/321, without verbs like 'delete'.Pass the test and this pattern moves unknown