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
sort
query 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=popular
even 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_date
field 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
user
field is only relevant if I'm requesting awarded badges (i.e. via/badges/recipients
or/badges/{ids}/recipients
). If the field is not always relevant, it should not be there. Instead, the*/recipients
endpoints should return "Awarded Badge" objects that haveaward_count
,user
, andbadge
fields.Tags, Badges, and Users all have
name
(ordisplay_name
) fields. So why can't I doinname=foo
when 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_count
should 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_count
would 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.