11 ms·
Do we need a web API?
- dang 7y agohttps://news.ycombinator.com/item?id=21600859 https://news.ycombinator.com/item?id=21600859 seems related.
- bilekas 7y agoThis is an interesting project, but there are very good reasons for having API's. Its just about is it the right tool for the job. I don't like their comment : 'They are just a necessary evil so the frontend can communicate with the backend'
- icebraining 7y agoI'm sympathetic to your position, but right now your comment doesn't carry much information. Why are they the right tool for the jobs? Which reasons are those?
- bilekas 7y agoNot to offer information, I'm just objecting to the stance they seem to make that : "Hey we're solving the 'API' requirement problem' when there really is no problem.. If your backend only communcates with an SPA and nothing else, then yup, this is a good tool for that job.
- hatch_q 7y agoActually this doesn't solve the core API challenges that SPAs have - versioning and compatibility. Clients will simply run outdated frontend code. Imho this is more trouble than worth as it will bring all the problems that we had with WSDL. If i'd do a SPA that has 'node' backend, i'd just use typescript to model the API and you can have shared models and compile-time type safety.
- gedy 7y agoI've used a similar concept about 10 years ago if anyone remembers Wicket[0], and personally really liked it. The challenge was the UI and state were all server side and difficult to keep memory usage down. I'd be interested in how this model works now that client side UI and state are much more capable. [0] https://wicket.apache.org/ https://wicket.apache.org/
- fmakunbound 7y agoI liked it as well. Web development had gotten way harder over the last decade.
- stopads 7y ago>Sorry, this site requires JavaScript to be enabled. For a flat blog post? Like, seriously?
- naringas 7y agowelcome to the web 2.0 cooming soon: web assemply web 3.0 which (I fear) might feel a lot like flash web pages from the early 00s. I hope I'm wrong.
- dekalbcountyman 7y agogot to get the fuck out of the industry professionally at this point
- frenchyatwork 7y agoWeb 2.0 was like 15 years ago now. Web 2.0 was "supposed" to be about separation of style & content and gracefully degrading JavaScript. I don't know want to call what we have now.
- lubujackson 7y agoProbably the "Web App" or "Web SPA" era, since everything seems to need to be a single page app that exists mostly in the client. There are some benefits, of course. Stable and standardized UI is finally available as a baseline for devs (much like early Windows/iOS software) and all roads are clearly leading toward a unified design model for phone apps/web/desktop. Bloat and needless complexity are the biggest issues at the moment, but all the frameworks seem to be (finally) focusing on becoming more snappy.
- BubRoss 7y agoWebasm doesn't enable anything new that couldn't already be done right now.
- naringas 7y agobut it will improve the ability to obfuscate webpages
- al2o3cr 7y agoCORBA called, they want their ideas back
- Ididntdothis 7y agoYup. Looks exactly like it. SOAP is not that different either. Add: my PTSD from a few months with DCOM is acting up :)
- icebraining 7y agoEven in JS, the Meteor framework was basically created to implement this. Except they actually implement things like validation, because as much as one may want to unify both environments, the reality is that exposing all your methods to the outside world may have some pitfalls, to put it mildly.
- collyw 7y agoWhat ever happened to Meteor? It was flavour of the month a few years ago, with many a frontend dev ranting about how great it was. Now seems to be forgotten about.
- pkage 7y agoHassles with installing NPM packages (they used their own package manager (!)), it was incredibly heavyweight, baked in reliance on MongoDB, and a weird templating language caused a kind of death-by-a-thousand-cuts situation. Plus, React came out and blew Meteor out of the water.
- dankohn1 7y agoOne of the early Meteor developers, Evan You, went on to create Vue.js.
- daxfohl 7y agoWe tried to use it in real life for smilebooth. It was nice for little sample apps but as soon as you hit something it was not designed for, the workaround was more painful than if you had just gone with a plain rest api. Scalability was pretty limiting too.
- theon144 7y agoIn my view you just replaced an explicit API built on top of known protocols, by a semi-magical implicit API. The problem of serialization, deserialization, versioning, endpoint design... They aren't an artifact, they're intrinsic to how Web apps are built. But yeah, for small projects I think this could be really neat.
- collyw 7y agoHaving a properly defined API gives you a nice interface to test.
- draw_down 7y agoMagic, implicit glue code is worse than explicit, handrolled glue code, imo. Do you need a web API? If you need to serve data to a web frontend then yes. Pick your poison, but you will have one. You can do a little dance that makes it look like you don’t have one, but in my experience that usually turns out worse than just writing the damn thing.
- fyp 7y agoPouchdb/firebase/backend-as-a-services were supposed to be the answer to getting rid of CRUD apis. The problem is authorization and validation becomes really difficult if you don't have a backend that you can trust.
- TOGoS 7y ago10 years of writing web application backends has taught me that yes, authorization is indeed the reason we all still have jobs. And the occasional handling of a transaction failure.
- gampleman 7y agoI think Firebase is a much nicer version of this in the sense that it essentially eliminates the backend altogether and allows the client to talk to the DB directly. It is definitely not for every project, but if your project pretty much only needs CRUD, it is amazing.
- cryptonector 7y agoThis. If you can just trust the clients, lots of things get easier. Though even then distributed systems are not trivial -- just look at Lustre (where clients in a cluster are all trusted, and if you don't trust some client, then it must use a proxy such as an NFS server running on a cluster member client).
- mvila 7y agoLiaison has nothing to do with a backend-as-a-service. You can host your backend anywhere you want. About authorization, Liaison doesn't expose anything by default. Only the specified attributes and methods are exposed, and there is an authorization mechanism so you can customize what you want depending on the user.
- aliswe 7y agoSeems like a WSDL endpoint from which you can generate eg. a client for .NET.
- thanatropism 7y agoDoes this force you to use node for the back-end?
- mvila 7y agoFor now, yes. Liaison is implemented in JavaScript, but the communication protocol (https://deepr.io https://deepr.io) is language agnostic. So it is possible to imagine Liaison being ported to any languages in the future.
- dekalbcountyman 7y agoisn't this a weak ass version of RPC/gRPC? https://grpc.io/ https://grpc.io/ - and thank God gRPC never took off the way Google hoped, it was pure ego and politics like the majority of OSS projects these days (in the web world)
- solipsism 7y agoCan you elaborate on the "ego and politics" part?
- dekalbcountyman 7y agoI have a very personal history with gRPC
- geitir 7y agoIs it bad? My operating systems class had a project based explicitly around it
- johnhenry 7y agoI wish the "really" wasn't taken out of the HN title. It gives the title a somewhat different meaning.
- mvila 7y agoI wish that too. :)
- zwetan 7y agoone word: security
- mvila 7y agoLiaison doesn't expose anything by default. Only the allowed attributes and methods are exposed.
- zemnmez 7y agothis is just JSON RPC? The "constantly serialize and deserialize it" statement is totally untrue too... The frontend makes 6 XHR calls just to render a single page and they're all just JSON. The idea of the frontend 'just calling' the backend with no API boundary is nothing short of atrocious for security. The only feasible logical end to this is ASP, which was an interesting idea when it was launched 19 years ago
- mvila 7y agoThis has nothing to do with JSON RPC. Liaison uses Deepr (https://liaison.dev https://liaison.dev) as a communication protocol. Regarding the number of XHR calls, to be accurate, it is not 6 but 4. Once Liaison is complete and optimized, the number of calls should drop to 2. Also, please keep in mind that Liaison is made for building single-page applications. So, using it for a simple blog might not be the right choice. And about your security concern, please head over here: https://news.ycombinator.com/item?id=21660785 https://news.ycombinator.com/item?id=21660785
- catern 7y agoReminds me of https://github.com/pkamenarsky/replica https://github.com/pkamenarsky/replica for Haskell
- Quarrelsome 7y agoIts good that expensive operations are explicit. Every now and then developers forget this and create garbage applications using frameworks that are set out in similar ways to this. Don't hide the communication layer pls.
- daxfohl 7y agoFirst Law of Distributed Object Design: "don't distribute your objects" --Martin Fowler
- mvila 7y agoA Liaison backend is stateless, so there is no shared state to worry about.
- k__ 7y agolol, coming from PHP, JSP and co, web APIs were the salvation. Monoliths are a big problem and merging frontend and backend into each other only made it worse...
- maxekman 7y agoA project using Elixir + Phoenix would be way cleaner if one would like to leave out the API in web dev.
- smitty1e 7y agoI daresay that if you need to: a) scale, and b) adapt over time you're going to find yourself decoupling and slapping APIs on both ends to adapt to the transport mechanism. So for a boutique app, you might get away with a client-server model.
- mvila 7y agoLiaison allows inheriting layers from each other. So, you can easily separate your API layer with your model layer, and you don't need to build a web API for that.
- daxfohl 7y agoThings like this have been tried many times before. (I made one myself back in the day). It always seems like a great idea up front, but never ends up quite working out. One of the big things is that the benefit declines over time. The amount of code reuse you get is sub-linear with respect to the size of the project. As the project matures, GUI code and back end code diverges. That leaves you stuck in a framework that ends up not necessarily optimal for server side, and not necessarily optimal for client side, and the amount of code you end up writing to coordinate between them ends up outweighing the actual business logic. The things that are successful tend to focus on problems that increase with greater than linear complexity as your app matures. Spend time focusing on these instead. Don't lock yourself into a framework that prohibits it.
- briandilley 7y ago> As the project matures, GUI code and back end code diverges. This. This is why ASP.NET, ServerFaces, JSP+Taglibs, etc. became a nightmare.
- mvila 7y agoYour point is valid, but Liaison allows you to build different layers if you wish. If you worry about cluttering the business logic and want to clearly separate the exposed API, you can expose subclasses of your domain models instead.
- daxfohl 7y agoI'd still say the established routine of publishing a public API and any shared code can go into NPM or whatever is the better approach. Liaison and tools like it essentially create a monolith exactly where something is screaming to be two separate services. You want to be able to deploy versions of server side and client side code independently. You want to be able to ensure you don't break clients that have web pages open when you deploy the new server version. You want clients to be able to run where JS isn't available.
- mvila 7y ago
- briandilley 7y agoRPC - this isn't anything new. When I started doing web development in the late 90s for about ~5 years I was the designer, front-end, and backend developer all in one. Then over time things changed to allow for specializations and we now have many different functions, and that's a good thing. RPC has a place, and it's not for web apps, at least most of the time. I've noticed over the years that JavaScript developers tend to try and put their JavaScript everywhere and I often wonder if it's because they don't want to learn other technologies. Don't get me wrong, I like a little bit of JS too - I even added JavaScript support to an old 2D Game engine using SpiderMonkey (before V8 was a thing) back in the day so that I could make desktop games with JavaScript. I just don't want to do _everything_ with JavaScript. Especially with so many interesting languages and technologies to play with these days. Are JavaScript developers today the PHP guys of the past?
- bradlys 7y agoI'd imagine it's probably a business thing as well. The idea that they can easily transfer people from frontend to backend tasks or have full stack devs who don't need to know two languages. Where I work, having one language has made things simpler when doing tasks. Don't need to look things up as much because you keep forgetting which one uses push vs append, etc.
- js8 7y ago> The idea that they can easily transfer people from frontend to backend tasks or have full stack devs who don't need to know two languages. Oh, you're a poet, right? I need you to write some legal documents. You are already expert in English, so it should be easy.
- z3t4 7y agoEasier then writing it in another language. And you would get even better when you also know legal talk. That happened to me when I switched to full stack JS, I became so much better at JS, made it possible to write much simpler code. Doing very complex things with basic language constructs.
- sm_sohan 7y agoMany years ago I remember using a similar shim on ASP.NET where you'd simply decorate a server-side C# method and you could call it from JS like any other method. Not quite the way done here, but it had similar goals to blend server and client. So far, these things don't work in practice because of the so many things that differ between a browser and server environment. https://docs.microsoft.com/en-us/dotnet/api/system.web.script.services.scriptmethodattribute?view=netframework-4.8 https://docs.microsoft.com/en-us/dotnet/api/system.web.scrip...
- z3t4 7y agoDont trust the client! Serialization should be abstracted. Btw. how does this work without serialization? :P (I guess its abstracted). With an abstraction layer, sending a request can just be an azync function call. There is also the option to keep the front end stateless aka server rendering like in old school web apps.
- thdrdt 7y agoThere are already frameworks doing this. For example Blazor (.Net core 3) and Phoenix Live View (Elixir). They write the Javascript for you but you won't even notice it. I don't have experience with Phoenix, but with Blazor I just write my complete SPA in C#. There is no API for communication between the server and client. Blazor creates all the JavaScript websocket code for me so I never need to write a single line of Javascript. And when you separate your business layer from Blazor you can always add an API in the future when you need one. Just create some controllers for your API and use the same business code Blazor is using.
- peteforde 7y agoAs has been noted in other comments, there is a growing list of technologies that implement some variation of RPC such that events on the client trigger server events. Those events persist any data changed and then regenerate the current state of the UI and ship the diff back to the client, ideally via calls to the morphdom library. What frustrates me is that it's not the API that is the source of complexity. ~80% of the pain of building most apps comes from managing the syncronization of state between the client and server. SPAs are the over-prescribed opiates here making the problem worse. Imagine what could be possible if you walked away from maintaining client state altogether. We did, and it's wonderful. StimulusReflex let me build a reactive tabular UI with sorting, filtering and pagination with 115 LOC, none of which is custom JS: http://expo.stimulusreflex.com/demos/tabular http://expo.stimulusreflex.com/demos/tabular I honestly believe that the existence of things like StimulusReflex and LiveView demand we question the ongoing utility of libraries like React. Popularity is not a good reason to use something, especially when you realize you could be radically more productive if you don't use it.
- ptx 7y agoThe readme says: "The current state of an instance (i.e., counter's attributes) is automatically transported back and forth." How does this work? Do you need some cross-network locking mechanism when you need to make sure the shared object's state doesn't get out of sync between client and server? What about passing object instances between client and server? Does it do what (I think) DCOM does to handle garbage-collection of cross-machine object references – keep-alives and timeouts?
- mvila 7y agoA Liaison backend is stateless, so there is no shared state or garbage-collection to worry about.
- vbezhenar 7y agoHaving clear API allows to have a clear boundary between trusted and untrusted environment in backend. If you don't check your arguments in REST endpoint, it's obvious bug and easy to spot. If it's just another method, well, you're not treating input in every function as a hostile.
- mvila 7y agoPlease see my answer here: https://news.ycombinator.com/item?id=21660785 https://news.ycombinator.com/item?id=21660785
- SahAssar 7y agoAs someone deploying frontend apps for a large site you should not underestimate how long people have their tabs open. I can get sentry error reports for versions that have not been deployed for months. Does this handle "API" versioning in any real way?
- mvila 7y agoFor now, with Liaison, API versioning is no different than usual: preserved endpoint for backward-compatible changes and new endpoints for breaking changes.
- flexblue 7y agoAs other have noted, someone caught on to the simplicity of RPC. It always baffled me how so-called RESTful APIs became popular, despite virtually all of them being RPC APIs with a veneer of rather pointless HTTP semantics. Virtually none of those APIs do anything to serve the intentions and goals behind REST[1]. Furthermore, many RESTful APIs end up being wrapped into language-specific clients anyway, because they have poor ergonomics in their raw state. I consider RESTful APIs the most significant anti-pattern not widely recognized as such. [1] https://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm https://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arc...
- brillout 7y agoSo true. That said, for an API consumed by third-party developers, REST makes a lot of sense. Otherwise, which is like 98% of the APIs out there, RPC really is superior. I've implemented a tool similar to what OP is building: Wildcard API [1] > rather pointless HTTP semantics. Agree. Actually, while implementing Wildcard API, I made sure to abstract away all HTTP semantics. With Wildcard, you don't think in terms of "HTTP verbs" but you think in terms of functions. Like you are naturally used to. > It always baffled me how so-called RESTful APIs became popular I believe REST became popular because it got lot's of exposure since all third-party APIs were using REST. [1]: https://github.com/reframejs/wildcard-api https://github.com/reframejs/wildcard-api
- tasubotadas 7y ago> the simplicity of RPC Simplicity? Have you ever tried to integrate distributed applications that do not share the same codebase? And calling REST anti-pattern tells me that you aren't that familiar with alternatives. >despite virtually all of them being RPC APIs with a veneer of rather pointless HTTP semantics. If you want to do RPC over HTTP and pretend that it is REST interface, it isn't really a problem of REST.
- paulddraper 7y agoPostgraphile is an example of reducing the number of layers: directly expose PostgreSQL schema (with row-level security) via GraphQL.
- Apaec 7y agoBut now you added the GraphQL layer on top of HTTP.
- namelosw 7y agoActually RPC is a good idea for front-end to talk to backend. Because the separation is more or less obligated if people wanted to do interactive web pages, instead of people want to separate them as different services for different problem domains. People who don't like write JavaScript can stay tuned, as WASM age comes, there would be a burst of things like this but not in JavaScript (eg: Blazor).
- brillout 7y agoHave a look at Wildcard API[1], it's similar to what you are building. I'm the author. I'm glad to see that RPC is getting more and more traction. [1] https://github.com/reframejs/wildcard-api https://github.com/reframejs/wildcard-api
- tasubotadas 7y agoIt's always cute to see JavaScript developers reinventing things that have been in the industry for 30 years. Welcome back RPC.