Last active
June 12, 2025 21:53
-
-
Save mcsee/d11fbd7a25ac1e15035c01166d1fbadd to your computer and use it in GitHub Desktop.
This gist belongs to Clean Code Cookbook http://cleancodecookbook.com By Maximiliano Contieri http://maximilianocontieri.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// user-api-v1.json - Original API response | |
{ | |
"id": 317, | |
"name": "Mr Nimbus", | |
"email": "[email protected]", | |
"nationalities": "Brazilian,Canadian,Oceanic" | |
} | |
// Later changed to this without versioning: | |
{ | |
"userId": 317, | |
"fullName": "Mr Nimbus", | |
"emailAddress": "[email protected]", | |
"createdAt": "2018-12-09T18:30:00Z", | |
"nationalities": ["Brazilian", "Canadian", "Oceanic"] | |
} | |
fetch('/api/users/317') | |
.then(response => response.json()) | |
.then(user => { | |
// This breaks when API changes field names and data types | |
document.getElementById('name').textContent = user.name; | |
document.getElementById('email').textContent = user.email; | |
// This breaks when nationalities changes from string to array | |
document.getElementById('nationalities').textContent | |
= user.nationalities; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment