Web Development – Building a Web Application Using Only REST API

web-development

In an experimental personal project I (along with a "team" of friends) did some time ago, we used a REST API to provide all data. The frontend (a JS-only webapp) then just called this API using AJAX. We used a homebrew version of OAuth and some makeshift token mechanism to handle authentication, and it worked quite well. We also developed a desktop application, which of course was very easy because we didn't have to modify anything on the server side.

The way I see it, there are advantages and disadvantages to this solution, one obvious disatvantage being performance, since the server has to handle more requests (one for the JS, CSS, HTML and one for the actual data itself). On the other hand, the high portability I mentioned above is a huge plus in my mind.

Now here is my question: is it worth it? Would someone who has more experience in this area than me recommend an approch like this?

Best Answer

Moving more logic to the client means limited processing on the server, so you can get by with a less performant server but it does require more powerful clients. Depending on what kind of application you are working on, this may or may not be an option. For an application with a significant number of users and features that require some amount of processing the savings of having clients do more processing quickly add up.

With optimized JS/CSS (bundled and minified) the amount of requests being done is fairly limited and it should not really be an issue. Remember that caching client-side is a big advantage and you should probably only have the initial request download the JS/CSS file. That being said, even if you push for server-side rendering you still need some amount of JS (to keep your application responsive as there are some things you can't or should not completely do serverside) and you still need the CSS for styling so that shouldn't influence your decision all that much.

Having a good REST API also means that you can have a wider range of consumers for your data. You are not limited to a single application and can integrate into other systems (like a widget in a CMS) and create better user experiences by having applications build around the platform they need to run on (like an iOS-specific app that looks and feels the way users expect).

One of the biggest issues you can expect to have is keeping your JS working cross-platform. More JS means a bigger chance of things breaking in a library or features that are not supported in an older or newer browser. With serverside rendering you have more control over the HTML being sent. The more you rely on JS, the more you will need to test on a wide range of devices.

Bottom end, with JS/AJAX you can get more responsive applications that can be made to work across a wider range of devices, at the cost of complexity because you are now supporting all of these devices.

Related Topic