Ask HN: What is your go-to example for a good REST API?
401 pointsI tend to always look to api.github.com when I need a little inspiration.
Anyone have some good examples of a particularly well laid out API?
Anyone have some good examples of a particularly well laid out API?
Comments (182) 67 threads
https://stripe.com/docs/api
I dislike Stripe's API. There are parts of it that just make no sense.
Say, you want to set a billing date for that fancy subscription. Yeah, just set a trial date until the billing date you want. Oh, and don't forget to charge a prorated difference (by hand, with charges)!
Want to upgrade that subscription? Yeah, cancel that subscription and start a new one. Oh, and don't forget to set that trial again!
Want to cancel that subscription but not until their next billing date? Hahaha, yeah no. You need to cancel now through Stripe and set up a process to cancel on your side. (Not the biggest complaint, but really. If I am having Stripe manage my subscriptions, they should do it all)
And I am sure there are many other details which would also drive me mad.
With all of that said, I think Stripe's API is definitely one of the better ones since my complaints are more functionality / feature requests than complaints about how it is set up.
My advice when starting a SaaS company: think through your subscription software early on, before it's a headache to even think about migrating away.
And what do you mean "upgrade"? You can move from one plan to the next and charges are pro-rated automatically for you.
I, too, loath the amount of time we've spent on subscription/billing but I'm just surprised that none of the issues you've listed are really causing any pain for us.
Although it’s kind of proving your point that the API could be easier to use/better documented, here are some simpler ways to do what you’re looking for:
* Canceling a subscription at the end of the billing cycle (no need to handle on your end): https://stripe.com/docs/api#update_subscription-at_period_en... * Anchoring subscription to a date (sorry! :( , this is undocumented but should be out soon): https://stripe.com/docs/api#create_subscription That said, agreed overall that our subscriptions support needs some love. We're starting to spend more time on exactly this, so would love any feedback you (or anyone else reading) are willing to share. I'm eduardo@stripe.com.* Upgrading a plan (no cancellation needed): https://stripe.com/docs/api#update_subscription-plan
Continue this thread — 1 reply
Thank you so much for the response! Complaining on the internet finally worked! :) I definitely hold nothing against Stripe, I still love you guys.
And why are there separate clients for Java and Android, which both use the same namespace differently?
And why do I need to set the API key as a global for the general Java client, while the Android client (sensibly) lets me give it as a constructor argument?
What do you mean by "Leaks the JSON structure of the document to the client"?
Some parts are great, other parts not so much. My thoughts echo the other's here.
It seems like the API is way too complex to do certain operations. Especially some very common use cases: for example, how to apply discount for next year for customers who already have subscription (we wanted to emulate how Comcast always gives you discount if you want cancel and took us weeks to make that working ...). I think they do want to fix all these issues but API is not designed to be easily expandable.
It's actually very hard to find a decent REST API :(
My points here are the following:
1. Think very very hard about how people will use your API <-- this is critical. This also includes operational characteristics of your API (performances, how often it is going to be called, optimization, etc.)
2. Make API easily expendable. Especially relationships between models. Sometimes, it is ok (or even better) just to organize it as "SQL wrapper". Like SOQL by Salesforce - but that again depends on number 1.
And in 2008/9 their API was always given as an example for REST APIs done right and it's still true today
https://www.twilio.com/docs/api/rest
They do an excellent job of providing a clear and robust API. I work there (but not on the engineering team), and still genuinely love the API itself.
Sorry for not pointing to specific examples, but things I really love to see in an API:
- Fully qualified URLs in all links (makes navigating and discovery in Postman a breeze).
- Ability to expand resources represented by links (even deeply nested resources) so I can get exactly what I need in a single request.
- The ability to specify what parts of the response resource to include / exclude, allowing me to slim the response to exactly what I need. More important in clients running on mobile devices where slender responses make a noticeable performance difference.
- The exact same URLs (including hostnames) for the test and production API, the difference between the environments being determined by the credentials used in the request. This greatly simplifies code in the client test and production environments.
- Security schemes that allow me to write serverless client applications (OAuth 2 implicit grant). This certainly requires more work by the API developer, but makes it possible to crank out all sorts of useful tools quickly, and massively reduces client IT overhead. This may not be appropriate for all APIs, but could be used a lot more often than it is.
- Along with the above, support for CORS so we don't have to mess around with JSONP and other hacks in the browser.
- If you make me eat your timezone, please please make it UTC. But spend a little extra effort and allow me to pass a timezone in, either as an account settings and/or request parameter (and a simple offset isn't good enough - support actual timezones so daylight saving is handled). It can be incredibly hard to analyze data in responses when you're constantly having to translate the time to your own to give proper context. Timezone support isn't fun but libraries make it pretty easy. This is more important in APIs that provide lots of transactional data.
- Let me attach meta data to resources - it doesn't even have to be a lot. Sometimes allowing me to slip in a handful of bytes removes the need for an entire database on my side.
- Be painfully explicit in error responses. State the obvious, especially in errors that are likely to occur at the beginning of integration such as issues with authentication, content types, payload structure, etc.
So much +1's for this. Even better if I can query for it.
All comments shown.
Couldn't load more comments. Check your connection and try again.