A backend developers journey through the Big 3 to figure out what is best and when.
In this article, I’m going to explain Django REST Framework and, at the same time, compare it to ExpressJS (NodeJS Framework) and Laravel (PHP Framework).
Express.js
If you check out the home page of ExpressJS, you will find it describing itself as a minimal and flexible Node.js web application framework. It is because Express.js is nothing but a very thin layer over Node.js, which is a Javascript runtime environment. Node.js, in its raw form, is very difficult to implement and Express.js hides all the complexities that lie within. We are able to use Javascript on the server-side because of Node.js and easily because of Express.js. Among all the framework's that Node.js has, Express.js has the most minimalistic implementation.
Laravel
PHP is most powerful full-stack web framework out there. It has an easy implementation, great community support (which only comes after a framework has proved it's worth), has a great guide to their implementation and its architecture makes it stand out. Laravel is already preloaded with things like sessions, cookies, caching management and are easily configured using their config files. With the help of its command-line tool artisan, Laravel makes development fast and keeps us unbothered from the trouble of maintaining a proper structure.
Django REST
A framework that claims that you can develop your applications much faster using it and is truly acknowledged for that is Django. Django is Python's most popular web framework and a great option for your higher scalable applications ready to be deployed after running some checks on its setting.py file, which assures you of the security of your application. Fast development and great security are the two things Django provides.
Let's talk about Django REST. Well, Django REST is a more abstract version of Django solely abiding by the Representational State Transfer principle. Django REST has subclassed and modified the Django classes to provide the user with more layered and we will handle most of the things so you don't have to worry approach.
Express.js
npm init
command too..env
file, but it won't have built-in support for that. We have to use the dotenv
module to load our environmental variables.package.json
is the file that keeps track of packages (It's a JS thing).Laravel
We can generate a Laravel app using Laravel installer or composer. Both will give you the structure as shown below:
Models
folder is missing from its directory structure. In the next versions, it will come preloaded with App\Models
directory..env
file and files in the config
folder to configure our application. In the config
folder, we have multiple files, one each for the app, database, queues and so on, keeping each component's concern separate.composer.json
is there for us to keep track of PHP packages we have installed and you already know why package.json
exists. The webpack.mix.js
helps us compile our CSS and JS files into a single bundle.make:choose_functionalities_from_the_listed_ones
will create a separate directory if it does not exist before creating a file for your functionality.Django REST
django-admin startproject projectname
. We will get the structure as follows: we have a one-parent directory and inside it, we have another directory that contains the files needed to boot our application.
manage.py startapp appName
. These apps are nothing but directories containing specific functionality. The startapp
command will give you a directory with the following structure.
init.py
file that is generally empty. It signifies that the current directory is a Python package directory.manage.py
file contains the code to execute our commands. (python manage.py command_you_want_execute
)views.py
directory.setting.py
file is the place where we configure our application. The use of an external module is required to load environment variables from the .env
file..html
files and are compiled using DTL(Django Template Engine) Or Jinja2(A popular alternative to DTL).ExpressJs
listen
method on its app instance which in turn calls the Node.js raw implementation of creating a server and since Node.js under the hood uses the http
module, your server is ready to serve HTTP requests.Laravel
Illuminate/Foundation/Application
object which requires the full path of your project's directory. Laravel at the time binds the interfaces with their component.Django REST
setting.py
file.Express.js
npm
libraries ready to contribute for validation.Laravel
Illuminate/Http/Reques
t objects' validate method.Django REST
Express.js
npm
package that will utilize these storage units for you and will provide you some easy implementation and extra features.Laravel
config
file.Django REST
get_response
method here calls the next middleware or the view in line.process_view
: Gets called just before executing view or middleware.process_exception
: When a view encounters an error, this hook gets called.process_template_response
: This hook is made specifically to run when the view uses the render method or returns a TemplateResponse
.setting.py
file. Seems easy.process_view
hook which is given view_function
(the view that's to be called) as an argument. A series of if conditions can be placed to check if we wanna apply this middleware here. Yeah, a little inconvenient.
Express.js
Laravel
Django REST
startapp
command gives us a new directory with Model.py
to store our model details, and a migration directory to store migrations that are generated from the command-line.Express.js
node-schedule
or node-cron
are the popular libraries that can help to schedule our cron jobs. Meanwhile, we have packages like bull and Kue for queues management in Express.js.Laravel
config
file. Laravel already has a built-in queue management service.Django REST
django_extension
which gives us a handful of command-line utilities to handle creating jobs, commands, show URLs, etc. Then, job scheduling can be done using the same approach as I mentioned for Laravel, but we are still one down with queue against Laravel even after using django_extension.
Phew! You made it this far.
If you are new to the programming world & after going through this documentation, you might be thinking very low of Express.js. Well, you should not. Express.js was not created as a full-stack web framework. It was created to make the dream that Node.js gave us - Running Javascript at server-side a lot more developer-friendly and easy to use. Though Express.js make us wander around the web, go through the documentation of modules and integrate it into your application on your own, but it gives you a much more detailed overview of your functionality. Express.js doesn't hold back in performance and scalability due to this. You can always choose Express.js if you want a fast performing, highly scalable server and want to explore the web a bit more.
Laravel already wins in lots of scenarios in this article. It is loaded with the necessities that an application needs for a good head start and is easily configurable. Laravel's great documentation makes it easy for any developer to work with it.
Go with Django if you want your application to develop at a faster speed and are concerned about the security of your application. Sites like Pinterest, The Washington Post, Instagram are built using Django, so you can't question the scalability of Django. Its DRY principle is the reason Django is able to do so much with very few lines of code and doesn't get heavy as the application continues to grow.
Performance of each of this framework is excellent, so don't worry about that.
At the end You cannot judge a framework in an absolute sense. It all depends on your use case.
Thank you for reading!