4 ms·
It depends. If your "API" is literally just a machine parsable version of data you have on your HTML, well, yeah, doing it the way the OP described as better w
by girvo 13y ago
It depends.
If your "API" is literally just a machine parsable version of data you have on your HTML, well, yeah, doing it the way the OP described as better will work.
But if you're writing an API to access a proper web application, it needs more than just data retrieval, and it needs ACL, and it needs to not show things to certain people, and allow bi-directional communication, and all sorts of other things.
That's where what the OP is asking for breaks down, and I don't think APIs are a "lie", perhaps they can be a leaky abstraction and sometimes the wrong choice, but they can also be super useful.
Its funny he brought up Amazon early on: they run entirely on SOA, APIs everywhere, controlling everything. Seemed cute to me :)
- desas 13y agoAll of those things can happen through the web though. Need access control? Use HTTP auth or use your own thing with cookies. Need bi-directional communication? Use HTTP POST, PUT and DELETE.
- icebraining 13y agoBut if you're writing an API to access a proper web application, it needs more than just data retrieval, and it needs ACL, and it needs to not show things to certain people, and allow bi-directional communication, and all sorts of other things. And HTML webpages don't have that? Let's take HN: * ACLs: ✔ I have an account and I can't post as other people. * Hide things from certain people: ✔ I can't see your email * Allow bi-directional communication: ✔ I can post this very message.
- jdbernard 13y agoMy big reason to have a separate API falls under "all sorts of other things": The machine API exposes data objects. The human API (HTML web pages) defines interfaces to manipulate the data objects. In the presentation layer (human API) I manage collections of data objects, conditional inclusion of other data objects, etc. The human API is not a simple resource-access system, but contains logic governing interaction and relations between data objects. The machine API layer is basically a controlled data access layer.
- rapala 13y agoThe human API also exposes data objects. It also sends extensions (CSS, Javascript) to the client that allow it to present the data and make additional API calls. This idea of extending the client program is part of REST. The machine API also handles interaction and relations. The representation of a collection object will contain URLs of the elements. There should be hints on how to compose a request that updates the object.
- jdbernard 13y agoSo I just spent half an hour trying to illustrate a simple counter-example, but for each of the half-dozen apps I have considered I see how it could be organized into a unified structure differentiating machine/human API by the requested content type. I'm not sure if I would prefer that in practice, but I think I am going to have to try it. The idea of having a single structure for the API is too elegant not to try.
- girvo 13y agoWorks for this case. Doesn't work for things I've worked on. :)
- leoc 13y agoWhy not?