0
0
Rest APIprogramming~30 mins

Versioning best practices in Rest API - Mini Project: Build & Apply

Choose your learning style9 modes available
Versioning Best Practices in REST API
📖 Scenario: You are building a simple REST API for a book store. Over time, you want to improve your API without breaking existing clients. To do this, you will add versioning to your API endpoints.
🎯 Goal: Create a basic REST API with versioning in the URL path. You will start with version 1 of the API, then add version 2 with a small change. Finally, you will print the API endpoints to show the versioning.
📋 What You'll Learn
Create a dictionary called api_v1 with two endpoints: /books and /authors.
Create a dictionary called api_v2 with the same endpoints but add a new endpoint /publishers.
Create a dictionary called api_versions that maps version strings 'v1' and 'v2' to the respective API dictionaries.
Print all API endpoints grouped by version.
💡 Why This Matters
🌍 Real World
Versioning APIs is important when you want to improve or change your service without breaking existing users. This project shows a simple way to organize and display API versions.
💼 Career
Understanding API versioning is essential for backend developers, API designers, and anyone working with web services to ensure smooth updates and client compatibility.
Progress0 / 4 steps
1
Create API version 1 endpoints
Create a dictionary called api_v1 with these exact keys and values: '/books': 'List all books' and '/authors': 'List all authors'.
Rest API
Need a hint?

Use curly braces {} to create a dictionary. Use colons : to assign values to keys.

2
Create API version 2 endpoints
Create a dictionary called api_v2 with these exact keys and values: '/books': 'List all books', '/authors': 'List all authors', and '/publishers': 'List all publishers'.
Rest API
Need a hint?

Remember to add the new endpoint '/publishers' with its description.

3
Map API versions to their endpoints
Create a dictionary called api_versions that maps the string 'v1' to api_v1 and 'v2' to api_v2.
Rest API
Need a hint?

Use the version strings as keys and the API dictionaries as values.

4
Print all API endpoints by version
Use a for loop with variables version and endpoints to iterate over api_versions.items(). Inside the loop, print the version and then print each endpoint and its description from endpoints.items().
Rest API
Need a hint?

Use nested loops to print each version and its endpoints. Use f-strings for formatting.