0
0
Rest APIprogramming~15 mins

REST vs SOAP vs GraphQL comparison in Rest API - Hands-On Comparison

Choose your learning style9 modes available
Compare REST, SOAP, and GraphQL APIs
📖 Scenario: You are working as a junior developer in a company that uses different types of APIs. Your manager wants you to create a simple comparison of three popular API styles: REST, SOAP, and GraphQL. This will help the team understand their differences clearly.
🎯 Goal: Create a small program that stores key features of REST, SOAP, and GraphQL in a dictionary, then filters and displays the features of the API style chosen by the user.
📋 What You'll Learn
Create a dictionary called api_features with keys 'REST', 'SOAP', and 'GraphQL', each holding a list of 3 features as strings.
Create a variable called selected_api and set it to one of the keys: 'REST', 'SOAP', or 'GraphQL'.
Use a for loop with variables feature to iterate over the list of features for the selected_api key in api_features.
Print each feature on a new line.
💡 Why This Matters
🌍 Real World
Understanding different API styles helps developers choose the right one for their projects and communicate clearly with teams.
💼 Career
Many software jobs require knowledge of REST, SOAP, and GraphQL to build or maintain web services and APIs.
Progress0 / 4 steps
1
Create the API features dictionary
Create a dictionary called api_features with these exact keys and values:
'REST' with features 'Uses HTTP methods', 'Stateless', 'JSON format';
'SOAP' with features 'Uses XML', 'Stateful or stateless', 'Built-in error handling';
'GraphQL' with features 'Single endpoint', 'Client specifies data', 'Strongly typed schema'.
Rest API
Need a hint?

Use curly braces {} to create a dictionary. Each key is a string and its value is a list of strings.

2
Set the selected API type
Create a variable called selected_api and set it to the string 'REST'.
Rest API
Need a hint?

Assign the string 'REST' to the variable selected_api.

3
Loop through features of the selected API
Use a for loop with variable feature to iterate over api_features[selected_api].
Rest API
Need a hint?

Use a for loop to go through each feature in the list for the selected API.

4
Print the features of the selected API
Print each feature inside the for loop to display the features of the selected_api.
Rest API
Need a hint?

Use print(feature) inside the loop to show each feature on its own line.