Eve: Building RESTful APIs with MongoDB and Flask Transcripts
Chapter: Fine-tuning your REST service
Lecture: Deploying your service
0:00 So far we've been using the Flask builtin server for running our apps. Now while it is lightweight and easy to use,
0:09 Flask's builtin server is not suitable for production as it doesn't scale well and by default it only serves one request at a time.
0:19 Some options available for properly running Flask in production are documented on the Flask website. On the website you'll find instructions
0:27 on how to host your app on all kinds of services or you can find instructions on how to set up Flask on your own self hosting environment.
0:38 In this lecture, we'll learn how to run our app on Gunicorn. Gunicorn stands for green unicorn, it's a wsgi http server for unix.
0:49 Actually, a pre fork worker model ported from Ruby's unicorn project. The good news is that running a Flask app on this service is very simple
0:57 Gunicorn comes as a standard Python package so all we have to do is pip install it in our environment.
1:09 Now that it is installed, all we have to do is launch it, pass the name of the launch script
1:19 and within the launch script what is the object holding the wsgi app. So in our case the app.py script contains an apt object
1:32 and boom, we're done, the server is running on local host port 8000. Now Gunicorn comes with a number of interesting and powerful command line options
1:44 the most useful probably are -w which allows us to specify the number of workers.
1:54 And that should be where we can say what is the port we want to listen to. So in this example, I'm launching our app with 4 workers
2:12 and the listening on port 4000. Right. As you can see, we have 4 workers, 1, 2, 3, and 4 all listening to local host port 4000.
2:27 Let's go to Postman and try to send a request. to our port endpoint people— it works. That's it, of course, you have many more options.
2:42 Gunicorn is just one of the many options you have, but surely it could be a nice starting point, and it also offers very good performances.