3 ms·
When it comes to writing APIs I feel strongly that you should be incredibly strict. 1 != ‘1’ true != 1 true != ‘true’ undefined != false undefined != null
by joshstrange 2y ago
When it comes to writing APIs I feel strongly that you should be incredibly strict.
1 != ‘1’
true != 1
true != ‘true’
undefined != false
undefined != null
etc
“Flexibility” in your API just means you are signing up for a maintenance burden for the lifetime of your API. You will also run into problems because you have to draw the line somewhere and people will be frustrated/confused since your API is “flexible” but not as flexible as they want. Better to draw the line at complete strictness IMHO. I dislike even optional fields and prefer null to be passed instead except special cases (like when null has a meaning, example: search endpoint where you pass the fields you want to search on and a field can have a null value).
I want people to be explicit about what they are doing/fetching when using an API I have written/maintained. It also encourages less sloppy clients