Hacker Read top | best | new | newcomments | leaders | about | bookmarklet login

its good to have that api but a significant difference is that it requires clients (and even servers) to know the pid of the process they are sending this fd to. this is unnecessary when you can make do with a socket connection (inherited of otherwise).


sort by: page size:

That's true. The difference is how much efforts is needed to do that using API.

What it brings is just a higher abstraction of that API which lets you easily to get work done.


I think that providing API to be used by standalone clients is far more better approach

If by "an API" you mean "JSON sent over the network" then I don't really see too much of an advantage in: database -> server side program -> JSON -> network -> client side program -> HTML -> browser renderer

over

database -> server side program -> HTML -> network -> browser renderer


That's interesting — the typed request and response objects that you get with an API SDK are certainly one of the biggest upsides, and I certainly see the benefit of having full control of the transport layer yourself so that you can add any common telemetry / logging / statistics at your leisure.

On the other hand, a benefit of a more complete API is that in typed languages you can tab-complete your way to success. With each endpoint a function and all the requisite configuration (API URL, etc.) bundled in, for basic integrations you may never even have to reference documentation, or if you do, very little of it, as your IDE finds functions/properties for you and you can read documentation right out their docstrings.


A better interface/API is really what I meant. The performance characteristics are probably worth the tradeoff.

The code is necessarily in different places, whether it's within a project or between projects. The difference is having an API that can be found without having to read all the code, and is well-defined and somewhat stable.

It's very "UNIX" to implement things as communicating processes rather than RPC or procedure-call-within-monolith.


Also, I might still want to do some things differently server-side in getInitialProps(), despite most of the code being shared. For example, clients might access the API through a load-balanced frontend, while on the server I might want to prefer talking to an API process on the same machine. Authentication might also be different. Of course these things (e.g. the API endpoint) shouldn't be hardcoded, but even then you need to get them somewhere, most likely a configuration file or an environment variable. And sharing these details (names of environment variables for example) with the client is not something I particularly like.

The API is neater, more expressive, and easier to use. Also, it is single-header only, easy for drop-in integration.

Actually, the API allows for both, whichever suits your needs. When doing buffer based processing, you can even add advanced automation, etc.

And that makes the API better because...?

Note one difference is that I'm talking about characteristics of an API, not particular code snippet. Although it's relevant.

So for a small application, I don't need to create separate API server. Nice one.

It allows a server produced by one organization to provide an API that remains efficient for future clients produced by other organizations without either changing the API to meet the needs of the other clients or anticipating every client's needs.

More to be economical in API design, rather than just server load and bandwidth.


For me, a big benefit is the tooling support. If the API is statically typed, I can easily find the headers I am able to set using my IDE. And for setting the date I don't have to check the http spec for which syntax I have to use for the date.

It's a tradeoff (isn't everything) but I don't think the cost is cleanliness/tidiness.

Your client (could be a web app consuming the api from the server) accesses the api like anyone else. You've created an api that others can build on - and you know that, because you're doing it yourself.

More to maintain. More cpu processing. Still a cleaner architecture though (compared to, say, having to maintain an external api for others to use while having a web app that talks directly to the db).


What? You can still use an api with server components.

The API would have the same delay and issues though, wouldn't it?

There’s definitely some similarities (both are generic-ish ways to get data out of an API). As mentioned in another comment, we’re still deciding whether to adopt an existing protocol or roll our own for those API connections. We’ve done the latter so far but it’s a work in progress.

An API is much easier to version-control, automatically check for compatibility and so on.
next

Legal | privacy