0
0
Rest APIprogramming~15 mins

Safe methods vs unsafe methods in Rest API - Hands-On Comparison

Choose your learning style9 modes available
Safe methods vs unsafe methods in REST API
📖 Scenario: You are building a simple REST API server that handles user data. Some HTTP methods are safe and do not change data, while others are unsafe and modify data.Understanding which methods are safe helps keep data secure and predictable.
🎯 Goal: Create a small program that stores user names and supports safe and unsafe HTTP methods. You will mark which methods are safe and which are unsafe.
📋 What You'll Learn
Create a dictionary called users with three users and their ages
Create a list called safe_methods containing the HTTP methods that do not change data
Create a list called unsafe_methods containing the HTTP methods that change data
Print the lists of safe and unsafe methods
💡 Why This Matters
🌍 Real World
Understanding safe and unsafe HTTP methods helps developers build APIs that protect data and behave predictably.
💼 Career
Many jobs in web development and backend programming require knowledge of REST API methods and their safety.
Progress0 / 4 steps
1
Create the initial user data
Create a dictionary called users with these exact entries: 'alice': 30, 'bob': 25, 'carol': 27
Rest API
Need a hint?

Use curly braces to create a dictionary with keys and values.

2
Define safe HTTP methods
Create a list called safe_methods containing these exact strings: 'GET', 'HEAD', 'OPTIONS'
Rest API
Need a hint?

Use square brackets to create a list of strings.

3
Define unsafe HTTP methods
Create a list called unsafe_methods containing these exact strings: 'POST', 'PUT', 'DELETE', 'PATCH'
Rest API
Need a hint?

Remember to use square brackets and quotes for list of strings.

4
Print the safe and unsafe methods
Write two print statements: one to print safe_methods and one to print unsafe_methods
Rest API
Need a hint?

Use print() to show the lists on the screen.