Eve: Why Using a Bloated Backend When You Can REST?

by Lukas Stracke, Backend Developer at Inovum Solutions, 09.02.18

Consider following situation: You want to develop a web application with a nice, beautiful UI and a database to store information. Obviously the way to go is to apply the MVC pattern and divide your app into database, frontend and backend. Maybe you design your frontend in AngularJS because it’s dynamic and comfortable to maintain and want to connect to the MongoDB where you store your data. The traditional way would be to design a big backend, e.g. using the Java web framework Spring. But what, if you don’t need all of the features that Spring offers you? Why using a complex framework that needs a lot of time to get used to and hours or even days to configure if you need the backend only for validation and authentication?

There’s another way to do this and it’s gaining traction, which is not to build a bloated backend for things that could be done in a more lightweight way. In our example we could easily build a lean and fast backend to connect to our database using a REST API. With MongoDB there are quite a few options to build such an API, such as Deployd or Eve. Eve is a Python REST API framework that not only gives us an easy way to access and navigate through our database via HTTP requests but also introduces a handful of convenient features. There’s no need to write your own backend validation functions using Eve, you just define your database schema in a few short lines and the framework does the rest. Furthermore it introduces document versioning using HTTP Etags, easy to use and indispensable if your database might be accessed by multiple clients simultaneously. But one of the biggest advantages may be the easy implementation of authentication. Out of the box, Eve offers several methods including HTTP Basic, token-based or role-based authentication. But since Eve is easily extendable using Python, you can also write your own custom authentication method. For doing this, you can of course use one of Python’s arguably biggest strengths, its libraries. Eve is based on Python’s web framework Flask, which delivers the extension Flask-Sentinel for using the popular authorization framework OAuth 2. This can be used to grant certain users or services access to your REST API using an access token system, easily and without time-consuming configuration.

So, the next time you are about to implement a big backend for a web application, where it may not exactly be necessary, maybe you should consider a lean REST API. In the end, your backend code is less bloated and also you spend less effort to develop and configure and as a result you have more time to improve the quality of your code, to take it easy – and to REST.

Schematic view of a REST API, source: https://maxoffsky.com/word/wp-content/uploads/2012/11/RESTful-API-design.jpg

Comments are closed.