In my opinion, one of the hallmarks of a good API is that it is self-consistent. It establishes easy-to-remember conventions and then follows them.
As I'm trying to adopt the 2.0 API, I'm finding a whole bunch of inconsistencies in the API that are making it really frustrating to work with. Here are some of the things that are really bothering me:
The value for the
sortquery parameter should always correspond to a field in the object of the returned JSON. It usually doesn't. For example, if I want to sort badges by theirbadge_type, I have to pass insort=type. It should besort=badge_type. (another example, for tags I dosort=populareven though it really should besort=count)I should not be able to sort by something that does not correspond to a field in the object returned. For example, I can sort Tags by "activity" (
sort=activity), but there's nothing in the returned Tag objects that indicates what that activity is. If we really want to be able to sort Tags by the time they were last used, then Tags should have alast_used_datefield that contains the timestamp of the last time the tag was added to a Question, and then I should dosort=last_used_date)I find it really annoying that some object fields don't make sense in all contexts. For example, the Badge
userfield is only relevant if I'm requesting awarded badges (i.e. via/badges/recipientsor/badges/{ids}/recipients). If the field is not always relevant, it should not be there. Instead, the*/recipientsendpoints should return "Awarded Badge" objects that haveaward_count,user, andbadgefields.Tags, Badges, and Users all have
name(ordisplay_name) fields. So why can't I doinname=foowhen requesting Badges? If you're going to offer searching by name on some things, you should offer searching by name on all things.
There are more, but these are ones that I remember right now. As I come across more I'll also post those.
award_countshould be on all badges, as when not associated with a user it means the number of times the badge has been awarded site-wide. (separate fields, e.g. total_award_count and user_award_count, might be better)award_count, but I definitely thinktotal_award_countwould be a better name. Making the semantic meaning of a field dependent on the context is a bad idea. Badges, IMO, shouldn't contain any user-specific information, because there's nothing inherent about a badge that has to do with a User.