Is it good practice to develop the API while developing the site so the site itself actually uses the API? Or is there a performance hit if choosing to do this?
For example, does anyone know if mature sites such as Facebook or Digg use their own API to CRUD (Create, Read, Update, Delete) or do they have their own backend? Thanks
It depends on whether it is necessary to use API. There is not any compulsion that you have to use API which does not make any sense in your application. If your application works completely fine without API then no need to think for that. Keep it simple unless it is needed.
There are more than 16,000 APIs out there, and they can be helpful in gathering useful data from sites to use for your own applications. But not every site has them. Worse, even the ones that do don't always keep them supported enough to be truly useful. Some APIs are certainly better developed than others.
Not every website has an API, and those that have do not always provide the information you need. Select the data you need and create your own API in minutes.
A good API thinks through its developer experience, providing complete, accurate, and easy-to-digest documentation. It also helps its developers by thinking through common use cases, the sort of things the real user of the API will want.
I doubt Facebook and such use their own API. There are a couple of reasons not to use your own API for the site itself:
I do think it's a good idea to have a low-level interface to the application that you can use without a browser per se, and that the site should use that interface to do its stuff.
That interface doesn't have to be the API itself, it could be a layer that's lower in level than the API, and that is used by both the API and the production website.
It's generally a bad idea if the API just duplicates the website.
i.e., the following is bad
# hypothetical example of bad duplication
def website_update_blog_post(request):
user = request.username()
ensure_logged_in(user)
post = Posts.objects.upsert(request.post_title, request.post_body)
trigger_notifications(post)
.....
def api_update_blog_post(user, password, title, body):
verify_login(user, password)
post = Posts.objects.upsert(title, body)
trigger_notifications(post)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With