jermbo / SampleAPIs

A simple, no fuss, no mess, no auth playground for learning RESTful or GraphQL APIs.
https://sampleapis.com/
MIT License
214 stars 54 forks source link

Wrong data API coffee #150

Closed yaronchristiaens closed 2 years ago

yaronchristiaens commented 2 years ago

The API of coffees is again filled with wrong data, which is stressful because in a few days I need to hand in my Android Studio project.

jermbo commented 2 years ago

The apis have been reset.

Given this has happened in the past, I think it's good to bring this up as a teachable moment. You cannot rely on data coming from any api as always 100% correct every time. This project, thay is for students, has the ability to change often, and or production code that is being itterated on. Always add some defensive code to ensure what you are getting is what you expect.

My suggestions are

  1. Take a snapshot of the data locally to load for your presentation. Ensuring no one can alter the data unexpectedly.
  2. Add a couple of filters to remove the data before building the ui.

The first option is a good quick fix and might be the solution you need for right now.

The second option is more a realistic example of code you will write professionally. My recommendation is to take some time and write defensive code. Sanitize the data coming from the api and filter out the bad apples before displaying the ui.

yaronchristiaens commented 2 years ago

Thanks for the help @jermbo , I've implemented an Iterator that removes the coffees that have an ID greater than 20. The second option you suggested works perfect.

thedamian commented 2 years ago

@yaronchristiaens I'm curious what the error was. Regardless you should try to give us more information. That way if there is something that is required other than resetting it then we can also look into it. Or talk about a "constant" version.

Remember also that the endpoints can be edited by you.