 Welcome to this video session. So in this video session, we'll be discussing Flask, which is a Python based micro web framework, mostly used to build web-enabled Python scripts. So let's also quickly see what outcome has been planned for the following video. At the end of this video, the learners or the audience is expected to develop an ability to use Python's Flask framework in building web-enabled Python scripts. And the following should be the prerequisite for the current video. Build a small REST API. Given two get variables with integer values, this API will respond with a value which is equivalent to the addition of the two variables. So let us see how it is all done in Python's Flask framework. So let me on e-dry, so it's my dry here. Within that, I have created a blank Python file with the name main.py, and the same file I am editing through PyCharm Community ID. The same file is opened here. So we'll start writing a code for this. The first line which your Python script needs to include if you want to use Flask is an import statement. And here, what we'll do, we'll use from clause. So from a module called as Flask, let us import an entity called as Flask. And we do need one more import, and that would be request. Add modules for our Python script where we can run our Flask. So the first statement to create a Flask-based app is to create a variable named app. And we'll initialize it with the object of Flask. And here, it will pass the name of this Python module. So we have initiated the app. Now, with the help of Python decorators, what we do is we associate a URL pattern with a method in a Python so that whenever, in case, whenever the development server of my Flask is running in the background, and whenever user request that URL pattern, the associated method gets called and whatever business logic or the code which we write in that method, it executes. So right now, we want to have a method which does the addition of a number. So initially, what we'll do is we'll create just a simple hello world like a Flask app and then we'll modify that to our REST API so that it can do addition of to get passed variables here. So let us first only define a simple root pattern. So we'll use app.route. And here we'll define the root URL pattern. And so this URL pattern will now be associated with a method hello. So here, whatever this returns, the method hello returns, that would go as an HTTP response to the browser. So I would like to just return a small hello world statement here. That's it. So we have it. And once we define this method, we need to make sure we initiate it. So what we do here is, generally we compare the name to equal to main. So we want to run this through a command prompt. So we need it so that the script only initiates the Flask development servers if it is run through as a, if it is run as a command line application. So now I can call app.run and I'll enable debug flag is equal to true because I want to capture the debug information as well. So this, the code here, once I have this code, what I need to do is I need to go to command prompt and run this application by using Python. And I have verified that my Python is 3.x. So I can now comfortably run this main.py. So now we have run that. And you should see this output. If you see this output, it's a clear indication that I don't have any errors and the development service is probably running. And you can see that these current web, hello world web application is being served on following URL, one, two, seven, localus and 5,000. So let us open a browser and let's see what output it is exactly printing at that point. So I have just observed this, whatever the method has written, what my method has written, it has written hello world, the same output has appeared here. Now the same method, we will now modify it so that I will be in a position to add two numbers. And these two num values will be passed to the flask backend as a get parameters. So let us see how it is done. So I'll switching back to my PyCharm ID and let us retain this as it is. And for addition, let me define one more URL pattern for it. So now I will specifically ask it to be add. So slash add, I'll put one more add pattern here, add slash add. And now this method, I'll call as add. And after this, okay, let us just keep it as a no need to add a slash because we need to construct a query string with a get parameters. So I'll just put this as add and this add will get two numbers as get parameters. And I would like that get parameters to be of form num one and num two. So what I'll do is, I'll directly return the addition of that. And I'm assuming that the get variable name will be num one and num two. So accordingly, I'll create two variables to hold the values where one. Now I need to retrieve the value from the query string. The method to retrieve that is by using request which we have already imported here. Request.args.get and just specify the name with which the get parameter will be passed. So it is num one for where one. And likewise would be for where two as well. So it is where two and here it becomes num two. Once I have them in this here in this form, I'll need to do an integer addition. So I'll call result is equal to though since they are string, I'll explicitly pass them to int. So that addition of two integers happen here. So I have a result variable. Now I will directly return result. And since the return being a numeric time, I'll convert that into str. So let us see if this works. I have saved it. Now let me say clear screen. I have a program saved here. Let me just verify app.root it slash add and I need to provide this two numbers as get num variables integer, integer addition. Yes. So we are ready to execute it. Let me remove this some spaces if not required. Okay. So let me run this once again. Python main.py. Yes, my application is running. Let me move to the browser window. So I'll see if my earlier hello world. Yes, it is working. Now I'll try the, our URL. So add. Now after add, I'm supposed to pass a get parameter. So it's always starts with a separator question mark. And then num one is equal to 10, a separator and num two is equal to 20. If this works, when I hit enter, if this URL works and if my code presumably, if it doesn't have, has any errors within that, then that should return with 30. So let us see. It says that name one, num one is not defined. Okay. Let me see. This is what generally is the output when you have improper code. It's okay. I think I got this. It says that num one is not defined. So what wrong we have done was they are not known. They are where one and where two. Okay. So let me save it and see what has, okay. So the moment I save it, it automatically reloads it. Whenever change is detected in that the developments are just loads it and upon loading, I don't find any error. So I can safely go to this and once again initiate this request again. Okay. Now you can see that it has returned with the addition of two variables. So we have taken a get form of request, but in some cases I might even take, for example, I might even prefer post method as well. So in that case, we always specify them as a string specifically here. It's a sequence of strings where it meant I mentioned a post and so even this works. Let me see. Yes. No error. Once again, I'll hit enter. So you will once again find that, for example, now if I make it as 25, it should see 35. But now remember that now since we have added a methods, now this method can accept. So this the decorator root add can now and this entire the flash setup here can accept HTTP get base request as well as post base request as well. So if you do not specify it, the default is get. And for this video, what do you think? Does plus support post method? You can pause the video and just go back a few slides back and you can rewatch the video and you can guess the answer from earlier video part. The answer is yes, it does support. We have seen that how it is done. We put when we are running that when we are defining a method in apps decorator root. So I'll show you as a quick. So I'll do a control that I'll show you. That's how we add a support for Python for post methods. So that's it for this video and a curious readers can go in detail through the official flash tutorial and documentation to explore far more powerful capabilities of flash micro web framework in Python. Thank you.