Learn to build REST API using Python, Flask and Postman | Pranjal Srivastava | Skillshare

Playback Speed


  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Learn to build REST API using Python, Flask and Postman

teacher avatar Pranjal Srivastava, Subject Matter Expert

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

20 Lessons (1h 18m)
    • 1. Introduction

      0:57
    • 2. What is API? How it works?

      1:24
    • 3. Different HTTP Methods

      1:21
    • 4. Setting up a virtual environment

      4:46
    • 5. Understanding routes and endpoints

      3:06
    • 6. Rendering HTML page

      2:48
    • 7. Query string

      3:39
    • 8. Flask GET request

      3:23
    • 9. Flask GET request (orders)

      3:57
    • 10. Flask GET request (members)

      2:48
    • 11. Testing different GET methods using Postman

      6:12
    • 12. Flask POST request

      4:37
    • 13. Flask PUT request

      6:24
    • 14. Flask PATCH request

      3:46
    • 15. Flask DELETE request

      4:11
    • 16. Flask Sqlalchemy SETUP

      6:30
    • 17. Flask Sqlachemy GET request

      3:45
    • 18. Flask Sqlachemy POST request

      5:56
    • 19. Flask Sqlachemy DELETE request

      3:26
    • 20. Flask Sqlachemy PUT request

      5:05
  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

39

Students

--

Projects

About This Class

Overview:

In this class you are going to learn about building REST API using Flask and Postman.

Understanding how the API works to deploying API is the objective of this class. Moreover, you would also learn fundamentals of the API like http requests, endpoints, routes, CRUD operations and much more in pragmatic style.

You could create APIs for different HTTP methods like get, post, put, patch and delete. And you would also learn how to efficiently store data to the database using flask SQL alchemy.

To test API's, you will also learn to use Postman. Postman is an API client that makes it easy for developers like you to create, share, test and document APIs.

Why You Should Take This Class?

If Technology is eating up jobs, then APIs are the teeth. APIs are everywhere and understanding the concepts of API and how to build would always give you competitive advantage over others. 

Future of development will be much more depended on APIs and if you are a developer or someone working in the technology domain, you need some working knowledge about APIs not just conceptual information but practical knowledge. And when you could build APIs and work with them, you could use your skills for a variety of roles in technology-based organizations. Be it Machine Learning or Data Science, Cloud services or mobile development, have developer skills over APIs could be a leverage. Moreover, this class is short and to the point that teaches with pragmatic approach.

What will students learn in your course?

Here you will learn following concepts:

  • Learn the fundamental concepts of microservices and API
  • Learn how to build rest API using flask, Sqlalchemy. marshmallow and postman
  • Learn to test API using Postman
  • Learn to perform CRUD operations: Create, Read, Update and Delete
  • Learn to build different HTTP methods- Get, Post, Put, Patch and Delete
  • Learn to build web app using Python flask
  • Learn multiple concepts like routes, endpoints, http verbs, status code and much more

Who This Class is For:

This course, is generally aimed for anyone who is curious to learn about Microservices and API. Whether you are Full stacked developer, back-end developer, front-end developer, data scientist, machine learning engineer, understanding of the API and microservices would be helpful.

Tools required: 

Pycharm IDE or any Python IDE

Meet Your Teacher

Teacher Profile Image

Pranjal Srivastava

Subject Matter Expert

Teacher

I am passionate developer, machine learning enthusiast, coder and bug fixer. Developed many applications on various platforms including python, java, android, php, etc.

I have worked over cloud on IBM Bluemix, AWS, and Microsoft Azure. Prefer digital marketing and SEO in my free time.

I am IBM certified Python developer.

Created own Programming language in Hindi .

See full profile

Class Ratings

Expectations Met?
    Exceeded!
  • 0%
  • Yes
  • 0%
  • Somewhat
  • 0%
  • Not really
  • 0%
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. Introduction: Hi there. Welcome to this course on rest API, where you will learn about how to be recipe using Python Flask and post man. My name is bronchial and I'm your course instructor for this class. Here in this course, you will learn fundamental concepts of APA, like how API works, what exactly API SDK matter. So you can see SAP wolves. What are the different types of history matters like get, post, patch and delete. And also we are going to learn how to implement them using Flask. And also at the end, we're going to integrate the database into our application using SQLAlchemy and the marshmallow. And also we're going to test our API using postmen that complete API development suit. And you're going to learn much more things here in this course. So if you're curious to learn more about API, start learning right now. See you in the class. 2. What is API? How it works?: Before starting to learn about building an API or how to code API, it becomes essential for you to know what exactly API is and how it works. Let me explain you with this real-world example. Imagine you went to the pizza shop, called the waiter, or the pace of your choice. Waiter noted on your order and pass it to the chef. And then shift starts preparing our desired bizarre and offer the preparation when the pizza is ready, he calls a waiter to get the pizza and brings it to your table. So here in this example, chef is a kind of server. You are the client and waiter is our API. Waiter whose job is to collect order details from the customer, pass it to a chef and brings, prepare a dish to the customer. So here you can see waiter who is a communication medium between customer and the chef. In case of API, client make an API request which hit the server and collect the response from the server and send it back to the client. In the same way, apra is a communication medium between client and the server. Not only client and server, it can be between two different services as well, who communicate with each other using API. So this is what exactly the API is and how it works. 3. Different HTTP Methods: We all know abs. I like Messenger or the communication between client and server are two different surfaces. Now, for any communication, we need a protocol. A protocol runs for the data or web. Here comes the HTTP protocol, which we can transfer our data or web. There are multiple legislative matters. Among them. You should know some of the most frequently used as trivial matters like GET, post, PUT, patch and delete. With the help of getMethod, you can easily recruit the data with the help of post method. We can use it to send me a new data into our collections or table. With the help of put, we can update the existing data which is already there and do a collection with the help of batch method, we can do some partial update into auditor. And the last delete, which is used to delete the data from the collection. So once the client send a request, it actually initiates the APA car. And these API calls uses these STDP matters, which sends to the server and get the response from the server and back to the client. These SQP methods are also known as STP works. Okay, so don't be confused. 4. Setting up a virtual environment: Hello friends, welcome back. In this lesson, you will learn that how you can create the virtual environment. So let's get into it. So before starting with how you can create a virtual environment, the main thing is that what is the virtual environment and why do we need them? So the answer is very simple. Now imagine that you are working on to web application. One application you are required to use Flask wasn't one. Whereas in another project, you require the version two. Now, just imagine that you are not creating an isolated environment for each of them. I'm going to install the Flask and this you are running your application. Then it will going to create a chaos. At a time. Only one project will go into work or inverse condition. None of them we're going to work. To remove this problem. We are here to use the virtual environment and it is a good practice while creating any web application. If you're having isolated environment where you're going to install all the required dependencies into the isolated environment, it will be better for your project as well. So here in this lesson, we're going to learn that how you will go into create the virtual environment. Okay, So without any further ado, let's get started. So here, first of all, I'm going to open a command prompt here and going to run a very, very simple command so that if we're going to create the virtual environment, this right, Python, F and M, then watch your ENV and give any name for your watch environment here in my case, I'm just going to give me ENV with simply means water environment. Okay? Now you can see that newly created data is there. We simply means that we have successfully created our watch environment. Now the next step is to get into this virtual environment and install our dependencies. You need to run the activate bash script, which is sites just into this directory. Now you can see clearly that V and V is, is there on the prefix, which simply means that you are now inside your version moment. Now here I'm going to install Flask. Flask is a very record dependencies for our project. So just simply write down pip install Flask in order to install any other packages you just need to use pip install and then x, y, z require dependencies or libraries. Okay, now we have successfully install flask into our virtual environment. Now let us open our IDE. I will highly recommend to use any kind of IDE because you'll get so many options and single-case. It will also going to help you while writing the code as well. So that's why I highly recommend you to use any kind of IDE. In my case, I'm using pie charts. You can also use Atom Visual Studio Code, spider, Tawny, and various other ideas are already present. You can just Google it and just download it. But H0, it is one of the most used id we used by professionals. It is considered as one of the best ideas for the Python developer. That's why I use this by chunk. Now you can see that I have already saved as simple snippet first-class. So just I return now flask and just it created a simple Flask application. So let me explain you. East line. Okay. So the very first line means that how you can import the flask distributed down from flask and pour flask. Then the next nine is to create an instance for your app, which is apical to flask. And then the very special character name is there. Then you need to write that equator, which is app.vue route. And here in the braces I have just give it a URL. So whenever we going to hit this URL, it will going to run this underneath Hello World function. And in return, we're going to return the string, which is hello world again. Okay? So this is very much required for routing purposes, okay? And make sure that if you want to add some more URLs, you need to create more routes. That simply means that you need to create more decorators as well. Now at last, which is their app or run, it will just simply going to run our application. That's how you can easily create a Flask application. I hope you understand that how you can easily create a Flask application. In the next lesson, we're going to dive into some more complex topics related to the flask and various other things, various other components of plus. So till then, keep learning, keep exploring, and stay motivated. 5. Understanding routes and endpoints: Hey guys, welcome back. So in my previous lesson, I have shown you that how you can create a simple version environment and then install some dependencies. And also, I've run a very simple Flask application, HelloWorld application to be exact. So now you can see there whenever I hit this URL, we got some logs for this getMethod. And you will also find that there is an HTTP status code is also there, which is 200. We simply means that our request, which we made for successfully retrieved. Okay, now as you can see, as many time I hit that particular URL refresh webpage. You can see the logs off get SQP matter created. Okay, now here, let me add some more things into my application, which is debug equal to true. So what it means that whatever changes and made into my application, we're going to reflect into my web app without rerunning our application. Okay, so that's the cool thing, isn't it? So now I'm going to copy the snippet. And you can see that it works very fine. Sometimes it's just hello world and hello bronchial. There's no need to rerun this application. Okay? Now you can see that it also prompted a message that it detected some changes and draw application. And of course, in upcoming lessons, whenever we're going to do some changes, we're going to find this message again and again. Okay? Now, here in this lesson we're going to add some more routes and some more new URLs. Okay, let me show you how we can do this. Let's write hello bronchial, which is my name, of course. And here I'm going to change the URL. And also I'm gonna reform at the file. Now let's rerun this application. We got an error. And this is very, very common error because I've used the same matter, although we have used a new route, Rangel, but it really to create a problem because you need to use the new method name. Okay? So keep this point in your mind that whenever you're going to create a new route, you will have to use new name for your method. Okay, let me read this application because we prompt and arrow right there. Now I just working fine. Hello world and then project. And here in the log section you are going to have this get for this URL and get for another URL, which is four oranges. And at the end we have 200, which is STDP status code. Okay, So I hope you understand how this work. In my next lesson, we are going to die some more new things about flask and the APIs. So till then, keep learning, keep exploring, and stay motivated. 6. Rendering HTML page: Hey coders, welcome back. We have just simply created a Flask application. Okay. You know very well, our web application with all of our page is incomplete. Have you ever heard that that this is a VAP app and there's no web page here willing to create a simple web page. And then we're going to render that particular web page into our application. So the very first thing which is required here is to create a new directory, which is template. And then inside the template, you need to put all your HTML files. Okay? So this is the beauty. You can see that it created a simple web-based with some basic tax into it. Okay? And one more thing you need to keep this interior mind that, that the, the matter which we are going to use, which is rendered template, it will look for the tablet folder and then flew into look for the file which you pass through the render template matter. So it is very much required to create this downplayed directory. Okay? Now here I'm going to create a new road where it, we're going to render our web page. Okay? We already familiar with that problem where we have used the same method name. Here we're going to change the name of method as well. And here I'm just going to write get esteem, okay? Because we're just running over the page. Instead of returning the simplest string, willing to return the HTML page. To do so, you need to use this render template method, okay? And you need to import the standard template here from flask, import flask, then render template, and come back to the disposition and just write down. Yeah, it is successfully imported. Now here you need to pass the name of your file, which is index.html. And in case if you want to pass some parameters, you can write the parameters with this file name, okay, which we're going to do in the later part. Let us check that it is working fine or not. This is our base URL then. And this is another URL. Hello Brandon. And this tear, I'm going to write HTML. Now you can see it displays the content of the webpage, just hello webpage. Now you can see the logs as well. We have the logs for base URL, the URL and the URL for our web page. This is how you can simply render your web page using random downplayed. Hope you understand. 7. Query string: Have you ever observed in the Google search query that question mark q thing? Yeah, exactly. Here in this lesson, you're going to learn about query string. Where are we going to pass some parameters using query? And then we're going to have some dynamic results into our webpage. Okay, so let's do it. The very first thing which we need to do is to create a new route for our query string. That's why I've just written down Q is a short one for query string. Okay, so now the next step is to collect the query strings, that query parameters, you can say that arguments you can see it is similar to the same programs which we'll learn in all school. Where are we going to collect some details from users? It will do the same thing, Okay? Now, here I have used this our variable to store our arguments, which we're going to pass through URLs request dot ARG. Arg is simply means arguments. Here. As we need to return the arguments into our webpage here using this return here. And the arguments will be in the form of key values. So that's why I've used this K, K four keys before values. And I'm going to use for loop here because I'm not going to pass only one parameter. I will going to show you that how you can pass multiple parameters as well, multiple arguments as well. So that's why I've used for loop here. And here in case if there will be no arguments, it we're going to return no query. Okay? Now let us check that it is working fine or not. You're simply write Q is. And then question mark. And then you need to pass the arguments. So what should I should pass here? Okay, Now let's just do for my name. I just write p is equal to practice to the full name of mine. And let us see that it will go into reflect into our picture. Here you can see that peers is our key. And this brownish was too is the value that I've created Daniel, that k and v thing in our application code on, let me do for another argument hello equal to world. Hello column for it is dynamic. It is deflecting into our webpage as long as we're just going to add into our URL. Now here I'm going to use the ampersand, which simply means that from here, the new parameter is there, the new argument is there. So you can see here very well that there is ps column branch was to then hello, world is there. This is how I have used the arguments from the URL and displayed over my webpage. So it is two most dynamic. You can create multiple web pages using this dynamic URL, using this query strings. So this is a very basic example. In my liters part, we're going to focus on the advanced use case of using this query strings. Hope you understand that how you can use the query strings into your applications. So they'll then keep learning, keep exploring, and stay motivated. 8. Flask GET request: Hey guys, what's up? I think now you are somehow for comfortable with Flask rest API. From this lesson we're going to explore different HTTP methods like get, post, patch, and delete. So first of all, I'm going to create a simple collection where we're going to store some kind of datas. In particular, it, we're going to store the details of order, order of custom pizza using HTTP methods through which we will be able to retrieve the order details. We can update them, we can delete them as well as we're going to create new orders as well. So through this, you'll be able to understand how you can perform the crud operations using rest APIs. Okay, so first of all, we're going to create a collection and I'm going to name it as order, okay? This oracle section, we are going to contain the order ID. Then it will going to contain the size of your pizza toppings and the crust. Okay? So let me choose the size and it will be small, okay? And the toppings, we're going to choose the seas and the crust. There are lot of options or AP level, and I'm going to choose the thin crust. Okay? So in this way, I created a collection which contains a single order entry. Now, we will create a GET method and you need to keep 1 in your mind that the default HTTP method is GET. So there's no need of adding the method parameter and to specify that which kind of SQP method you're going to use. This getMethod is the default one, is simply write down the decorator that route. And then you need to add the function name, which is get order. And here we're going to return the response which we are going to contain this aura collection. Okay? You need to import the library disliked Mac response and justify it makes dictionary into better json format. Okay, that's why I'm using this just in a package here. Let me run this application. This is our base URL, HelloWorld. And now here you need to add simply that slash order thing. And through here you are actually retrieving the order details. You can see this is the single entry which we have added into our recollection, R1. Okay, in the latest part, we're going to create a function through which we can add some new orders into it. Okay, now, let me show you in this log section, you'll be able to see that whenever we hit that particular URL, that getMethod entry is there inside your lock. And at the last row we're going to have the status code, which is 200. So this is all about get S3 method. And next lesson we're going to focus on post SDV method. Till then, keep learning, keep exploring, and stay motivated. 9. Flask GET request (orders): Hey friends, welcome back. This lesson is actually the extension of the previous lesson. Here, I'm going to add some more things into the getMethod. So previously, we have the getMethod, which is actually retrieving the order details, the complete collection details. Now we're going to only focus on that particular order. And here we're going to pass the parameter. Here the parameter will be your order ID. So whenever you're going to pass the order ID, we're going to access that particular already details. So here we're going to, actually, we're going to actually add some filters into our GET method. So let's get into it. I've also created a new file, new order dot p y. And here I'm going to add the matters related to the orders. And the euro will be the same orders. And now here we are actually passing the parameter. So you need to mention the parameter variable, which is our ID here, okay? And you need to put it inside the double angular braces. And now I'm going to define the matter, the get order method. Now here you need to pass that Order id as a parameter. Previously, we actually do need any kind of order ID. That's why we didn't use any parameter inside that previous method. Now, here we actually need this order ID. And first of all, we're going to check that particular order id is really inside our collection or not. If it is not inside of a collection, it will simply response that this ad is not present interview collections. And if it is present in your recollection, it will go into simply, it really just going to return the values of that order ID. This, right? Our ID not found. Okay, now let us run this application. And here you need to use this order URL. This is the basically the collection information. Now, this URL contains the information of the order ID one. Okay, I hope now you understand that what is the objective of this lesson? Now let me create one more order details so that it will be a little bit more clear that what and why I've created this, another GET method. Here, I'm going to add some comment that get order details using other IDE. And here it is my collection. I'm going to copy this detail of Oregon and do some minor changes into it. First of all, and this needs to change the order ID. And then I'm going to change the size, the toppings, and the crust as well. Now, let me read in this application order and then slash order to now you can see it is basically to trimming the audit to details. And this is the main base URL, okay? So in this way you are able to access the particular order details using this order ID parameter. Hope you understand that how you can use get matter into more advanced way. Then next lesson we're going to learn more about STP matters. Tilden, keep learning, keep exploring, and stay motivated. 10. Flask GET request (members): Hey guys, what's up? In my previous lesson, I have shown you that how you can access that particular order details. So in this lesson, we're actually going to focus on the order details member. Like it can be a crust, it can be your toppings. It can be the size of the pizza. Basically in an hour visit add, there's no need to have this feature, but it might be quite possible that whatever application you're working on, there will be a condition. There will be any situation where you need to access the members of any particular item. Here, ruling to create a matter new getMethod for this purpose. And here you need to pause the two parameters. One parameter is going to contain your order ID details, and another parameter we are going to contain the specification of your order, which can be the crust size and the toppings. So you need to search that particular order is present inside here or not. And if it is present, then it will going to check that whether that particular specification of your order is present inside your order it is or not, then if we're going to return the response accordingly. Here, I have created a new variable, which is item here. And it will going to look for other ID and then get the details of the member. And if it is there, then it will going to move further. And if it is not, it will going to simply return that that order not found. Okay. I'm going to check it out that it is working fine or not for this crust. Here we've got some error. I think I have not changed the name of my method. That's the problem. That's why we're getting this problem because of existing the endpoint function, you need to change the name of the method. So here I'm going to use get item details and rerun this application. Now let us give this URL. So now you can see that we are able to access the detail of the particular specification of the business or the size, the crust. Okay, now let me change the order ID as well. So you can see that we are able to access the other ones size as well. So this is how we can access the member of order details. The next lesson we're going to focus on a very important SDV method which is post. So till then, keep learning, keep exploring, and stay motivated. 11. Testing different GET methods using Postman: Hey friends, Welcome back. Here in this lesson, you will learn about a very, very popular tool in the field of API, which is Postman. Postman is basically our API platform through which you will be able to build and use APIs. It simplifies each steps of the API life cycle and it is very much popular. And with the help of this post man, it is basically complete API development suit. And it contains so many built-in tools that will support you in every stage of your APIs. Like it can be design, it can be like automatic testing, monitor your APIs and even published the API. This is the place where you can do multiple operations from one place. Okay? That's why it is very much popular in the field of API development. So what I'm gonna do is I'm going to test for APH I've created till now into this postmen. Basically we have created different flavors of the getMethod. So we're going to go through this different getMethod and we're going to retrieve different informations which we are getting through. This is one of them. Then, hello world and hello fragile. And we're going to do for the query string. I'm going to create a new tab here. And here. Before it I'm going to do for STEMI. You can see we were able to access the content of the stimulus bill. Now here you will get an option which is preview, and here you will be getting the preview of that particular estimate page. Now I'm going to open a new tab. This tab, you're going to test for that query string, which is Q as I think. Yeah. So with this q is if you don't pass any parameters or arguments, it will going to return no query. Okay, so let me do for that particular, particular case and you can see that it return the node query. Now, if you want to add like, you know, the parameters, you need to use that question mark q thing. Before it. I'm going to save each of the methods which I have tested into a new collections which is busy app. And here I'm going to store, I'm basically going to save all the request in future. If I want to test all these kind of get recursion, we can easily run that particular collection and it's going to check for each and every request which we're going to put inside this collections. Here you will get an option of folk history. Then there's APIs, then there is some options like runner and various options you can see into this postmen dashboard. Now here, inside, here you can see the patterns than authorizations. The header body body is like where you can pass some information with this with this SDV method. In case of post PUT patch where you need to pass some inflammation. You can do it here with this body options. Then we have graded quiz groups than tests and settings. So many options out there, you just write Q. And then question mark here you can see that it's selected by its own query parents. Here, P is the key and value is furniture was too. If you want to add another parameter, you can just simply tap here. We're going to create, you're automatically add the ampersand symbol. Create another argument which is full bar. You can see it is you're learning the thing that p is prime shovels to and Foobar. Now, I'm going to save this data as well. And other than it will going to also check for the orders which we created earlier. I'm going to open a new tab. Then your orders. And here we are able to access R1 and R2. And I'm going to check for that. Others. And with order one ID or two more Get matters are there suggests right. Order one. And here you will get the order details of order one. Okay? Now I'm going to open a new tab, and here I'm going to exit the particular member of R1 which is crossed here. Now here it is some kind of, you know, There's a problem with the case sensitive. You need to add this capital C here to access a particular member of that orders. This is the way through which you can use the API or you can say taste you APIs using Postman. And further parts when we're going to perform as to be mattress like post patch. Then we're going to pass some contained into body and do some more experiments with postmen. Till then, keep learning, keep exploring and stay motivated. 12. Flask POST request: Hello friends, welcome back. In my previous lesson, I have shown you that how you can use postmen with different flavors of getMethod. In this lesson, you will learn that how you can use another HTTP matter which is posed. This GET and the post matter are the most popular aesthetic matters. Okay? So why do we need this post STP matter? With the help of post matter, we are able to create the new collections. Okay, let me show you that how we can create a new collection using both methods. So I have copied that getMethod snippet and now I'm going to do some minor changes here. So here, I've already told you that by default, the estradiol matter is getMethod. And if we're going to use another methods, you need to mention it. Here. I've mentioned it. The post method, okay? Now here I'm going to pass some parameters and the parameters will be our id. Then we will go into actually pass the data in the form of JSON. So here I've created a new variable. So whatever request, whatever request suggestion will be, all of the fields we're going to store inside this request variable, okay? Now, first of all, we're going to check that particular RID is their intellectual naught. If it is already there, it will go into prompt, an error that our ID already exist, okay, in case it is not there, then whatever fields which are inside the Jason the request is isn't that particular foods we're going to be stored inside our collections. Okay. Let me show you that how it will going to look like. So here I've also added the SQP status code for the error, which is false, not, not. Now, you need to simply write order and update. And here, just write this order ID and the, the content of the Json. Okay, so we're going to add that Jason foods and draw our collections. And in response it we're going to simply send the message which is new order created. And we also need to change the HTTP status code as it is successfully doing its job. So you need to change its HTTP status codes as well. So here I'm just going to simply write down two, not one. I'll just open this post man. And here, let me remove all the unnecessary tabs. And simply I'm going to open a new tab. And here you need to raise that URL and just write order one and send as it already exists. So if we're going to prompt an adder, okay, we got a problem. Will not send the request. Let me try it again. Okay? You need to pass the decent thing here, okay? You can not, most are empty json, okay? You need to add the things. We are again getting this problem. Oh, we forgot to rerun our application. Now let me check. Okay. This is the thing which I'm going to add a new order into my collection. So as you can see, Autobahn already exist, so the new content not store into our collections. Now let me change the order ID and now it is successfully created. Straw slash will be not there, I think. Now it may send. Now you can see we have a three are the tails. One is order of 12, which is by default, and R3, which we have created using the Postmaster. In this way, you can use post method to add content into your collections. Hope you understand in case if you have any kind of doubt, you can ask me in the Q&A section. Will then keep learning, keep exploring, and stay motivated. 13. Flask PUT request: Hello friends, welcome back. In this lesson, you will learn how to use another HTTP method, which is PUT method. Earlier we have discussed about GET and post method, where GET is used to render template and retrieve the content of the collections. And with the help, of course, we can easily add new collections into it. Now with the post request, we can easily update any content of the collection. Therefore, we can easily update any selected or ID. So without further ado, Let's get into it. This is the postmen dashboard. And here you can see that we have some set of order details into our collection. Now let us create a new matter for the PUT request. Before it. I'm just going to open a new tab and I'm going to select the request, have to put and add the basic tutorials into the body segment and the whatever order ID which you want to update, you need to also specify them in the URL. Now, selected json format and the row form. And here this is the JSON for this order one. Now here I'm going to change some kind of details into this. Now here you can see for order for it is thick or thin crust. So I'm gonna change it into the thick crust. And I also want to change the size as well, from small to large. And as well as I'm going to change the toppings. So here you can see the order four, which is already created. We're actually going to update each specification of the pizza, size, the crust, and as well as toppings as well. So this is the major difference between PUT and the post request. Here, with the help of postmaster, we're actually adding some kind of thing into our collection, adding some new auto tails. And whereas with the help of PUT method, we can do either update or as well as add new content as well. Okay, So this is an extension of Postmaster in short, you can say. So here we are in, into our ID. Here I'm going to do some changes. Okay, so first of all, we need to change the method from post two genes to put method. And here this will remain, I'm going to add it here. As first of all, we're going to check that the order ID, which is passed through the URL is present into our collection. If it is present in the collection, then we're going to update their thing. But in case the particular order id is not present into our collection, then if we're going to create a new audit trails into our collections. Okay. So it might be quite confusing. Let me show you that how it will going to work. So here, you need to add this thing here. And I'm going to change the message as well. Like rather than this error message, I'm going to just write down that our order ID is now updated and in case if it is not present, so in that case we can pass this message set. New order is created, okay? I'm going to paste it over here as well. So this is the matter which I've created for put HTTP method. Hope you understand that how it looks like this minor changes as you can see that in the post method, we just added into that particular container, into a collection, just checking out that, that particular thing is they are not. Here. There's one thing you need to keep in your mind that in post matter, if that particular audit or add is already present in the collection, then it will going to give a message that that order Audi is already there existed. In that case, our new things, we're not going to be added into the collection, but with the help of post, we can easily add that into our collection as it is, update them. So let me send the request to this postmen. We got this error. We already familiar with this error. This error is simply occurs that application is not in running mode. We are getting, okay, there's already problems there, okay, you need to change the metronome as well from postorder details. So I'm going to change it with already tails. As you can see, the URL for post method and the port matter is same only we actually need the mattered. So you need to change the method. This is the main thing which you need to change here. Now it is read on this application and send the request to this postman dashboard. And let us check it out that it is working fine or not. As we have. Restart our applications. So we need to add those already tools into our collection once again, okay? So I'm going to add some to the order of four with that same configurations which are 12 has as well as three. Now here in order for will not going to change this to encroach into our thick crust. Let me show you how to do it to work. So you can see here we've got the masses that are updated. Again. Use this get request to check the update is made or not into order. So here you can see that changes which we made using that PUT request is now I've worked very well. And now let us do some more things. I'm going to create art or five and send this request algebra. I'm going to change some configurations of the space as well. Now you can see that new order is created. So as I said earlier, that this PUT request is the extension of the post method. So if that particular order and it doesn't exist it to a collection, then it we're going to create. And if it is existed that it will be to update at large. We're going to save this, PUT request into our Postman collections. In later on. We can use it, tell them, keep learning, keep exploring, and stay motivated. 14. Flask PATCH request: Hello friends, welcome back. Here in this lesson, you will learn about the new SDV method, which is batch. The previous lesson you have learned and how you can create the matter for PUT request. Here, you will learn about the patch as well as you will also learn the difference between quotes and the patch as there does the same thing. Input, it will going to update the ping, but before it, we're going to check that particular resource is available there or not. If it is not there, then if we're going to add it into our collection, and if it is there, then it will go into that particular existence one. But badges always are updating thing, okay? So Pat simply means the part of something. Okay? So here, not like a PUT method where you need to pass each and everything. In our case, we have size, toppings and the crust. Now, in case if you want to change the crust while using the put method, you mentioned all three things before updating the crust. But in case if you want to change the crust using the patch request, you just need to give the crust and the value which you want to add on which you want to update into the cross section. So this is the major difference between both the batch method. Let me show you that how it will look like into the postmen dashboard. Before it, we're going to add the comments and on each matters or why we use when we need them. So here it is, our postmen. And here you can see we have already run the get request and we have three orders into our collection right now. Now, I'm going to do we're going to change the details using the PUT request first. Then I'm going to show you that how we can do the things with the batch request. So here in the body section, let's travel this right order one. And here you can see the pink grossed small dopings is there. So here I'm going to change it if it cracker crust. And I'm going to send this request. So it updated the thing here in the order of one. It changed the toppings, it changed the cruelest. But in case you just want to change the crust only. Moved size toppings and this as well. And your cracker, that's right, tin crust. Now send the request. Now here you can see it could move the size and toppings as well. It's actually modify the schema, okay? But this is not a thing which we want right now. You want to update only the crust without compromising the sides and toppings. So here comes the patch before it. We're going to make it that make the changes into our order one to the previous one. Here. There is cross cracker crust. Here we have dopings as well as size. Now here with the half a batch, we're going to change only the crust. The crust. Now, let me run this GET request. So here you can see it's changed the crust without compromising the other two values. So this is the difference between PUT and the patch request. Hope you understand if you have any doubt, you can ask me. So that's all. Till then, keep learning, keep exploring, and stay motivated. 15. Flask DELETE request: Hello friends, welcome back here in this lesson we're going to cover the D part of the curl operation, which is delete. So here we're going to provide the order ID and just we're going to delete that particular entry for our table. Here. There is no need to provide any Jason because we're not going to insert or update any details into our table. The only thing is we are here to delete their production already detail. The only thing which is required is the, Alrighty. So first of all, we're going to change the method name, which is delete right now. I want to remove some lines which are not required here. We don't record anything like this. And just really going to add that delete thing. Just write delete the ELN shortfall, and then order and sends that order. You need to mention the order ID which you have passed through your URL. And you need to change some response as well. Okay, one more thing you need to add here is to like if their particular order id is not presented table that it will return the error. And this particular line as well. And I want to remove this message. Sure, masses at error. That particular rRNAs not present into the table. That's why we are getting this kind of response. Okay. And yeah, there's no completed I don't think so that anything is required. Let's change the status code as well. This is folded up for just add are not found. And two is 0. For. This simply means that we're successful related to that particular order details. Okay. Now let us open the postmen to test this delete request. So first of all, we're going to send the get request to retrieve the alrighty details regard same problem again. Regime the method name and resend the request. Not send the request. Okay. There's no problem in our code snippet, what is delete? Something is still missing. Yeah, getting this error. Okay, we have fathered two. We run this application. Now you can see that when we have sent a GET request, we got the order one and order to details. Now here we're going to delete order to another one. Okay? So you need to pass the URL just like this. And also you need to provide the particular order ID that you want to delete. So here, first of all, we're going to delete the order of 11 is deleted. Definitely check it out. By sending the GET request. Again. You can see only order to left. Now I'm going to do this, A2 as well. Genes and name. This has all the information you can see from here. You can see the request school, which is 204. We simply means that it successfully deleted the order details which we have provided. Now. We have deleted. 16. Flask Sqlalchemy SETUP: Hello friends, welcome back. We all know about Flask framework legacy as it enables us to build web applications very quickly with Python. You, in this lesson, we're going to build rest API with Flask and some other supporting tools and libraries. In this lesson, we will build this app. We will want to perform different kinds of requests, STP requests like get, post, patch and delete. Moreover, this app will also contain different matters through which we will be able to communicate with our database, our SQL database, or this, we're going to use SQLAlchemy and the marshmallow imported this flask SQLAlchemy. Okay, now we're going to do some kind of configurations and do our application. So the very first thing is we need to have the database. To create database, you need to link this database URL into your application. Just write down app dot config, then SQLAlchemy, database URI. And here you need to provide the database URL. And inside it we're going to provide the name of whole database. Basically this SQL k-means is the kind of autumn, which means Object Relational Mapper. When with the help of this object relational mapper, we can provide an object-oriented layer between our relational database and object oriented programming language without knowing to write the SQL query is. It is very much popular while using with Flask as it is very easy to implement, very simple. And also helps you to, I hope your code very quickly. Here. I've used this flask SQLAlchemy, and now I'm also going to disable the notification which are made by the whatever gene is being made into the database. The session we are going to be generated. I want to disable it. Now here, when you create an instance for database as well, we have App, which is the instance for our web application. And now we have database instance. And here we have provided the app instance. Here we're going to create the table. Let's write down class my app and db dot model. You create a table here. You need to mention whatever columns you want to add into your table. Like I want to mention this, RID the size of pizza toppings of the pizza. The pizza. These are some basic specification for the visa. And here we're going to describe their datatype or order ID. We're going to use the integer datatype. And this order ID is particularly for identifying any bizarre order. So here we're going to set it as a parameter tree for our table. And then size. Size could be the size of your business or it could be small, medium, large. And here we're going to use the data type string. Same with toppings and the crust. To paste it over here. 500s simply means the length which are allowed to be inserted into that particular column. Okay, so here I have given 500. No, it's too much, but still I've given it. Now here. I'm going to create the database. To do so, you need to use db dot create it. We're going to create the database and a table, which we mentioned here and the columns. Now, we're going to use very important another flask library, which is Flask Marshmallow, is a thin integration layer for flask, which is our Python framework, and the marshmallow, which is particularly used for Object serialization or deserialization. With using this Flask Marshmallow, we were going to able to add additional features to the marshmallow included the database URLs and whatever we're going to add to it. So why do we need the marshmallow here in this application? It may explain you in a layman manner. So we are storing our information into the structural format, the RDBMS format. And now we are actually creating the API, which will be in the form of JSON. So to do so, to convert your structural data into JSON format, we need to use this marshmallow. So here we are using this marshmallow for this purpose. Okay? Now, after importing the marshmallow library, you need to define the schema. And here, this is very easy, just you need to mention all the fields, okay? And then in the format, format you want, I am using the JSON format, okay? So now you can see this, this is very easy to implement the marshmallow thing into your web application. Now I have read in this application, and as we read on the application, so it will going to create the database. The database which we have created this my app dot SQLite. Okay, So hope you understand how you can create the database, the tables, Then create the columns of the table. Then how to convert you structural schema into jason format. Okay, so in the next lesson we're going to jump into more complex topics related to floss as well. K-mean, Dylan, keep learning, keep exploring, and stay motivated. My dear friends. 17. Flask Sqlachemy GET request: Hello class, Welcome back. So in my previous lesson, I've shown you that how you can use the floss as well, k-mean to create your database and the table and the marshmallow for CLL addition and deceleration of your data. Now here, we're going to use the get method to retrieve the content of our relational database, okay? Now, after adding the decorators, which is used for routing, and you need to mention the URL. So here I've given slash orders. Whenever we're going to hit the slash order URL, we're going to actually running this method. And this method we're going to retrieve all the contents which are stored into our database. Just write definition, get order. And yeah, let me mention it again. If you're already familiar that it's very good that this string method that GET HTTP method as the default one. So you don't need to mention it over to you. Equator. So whether you're using boast both patch delete or any other restaurant method you need to mention. But when you are using GET method, there's no need to mention it, oil, the decorator. Now here, just like the SQL query, we're going to add the query here, which we're going to display all the information and displaying to our application. So let, I've already discussed about the marshmallow. Okay, now here we need to create the Marshmallow schema. So here's this. I wanted to write, my apps key might fall to my app schema. Here you mentioned men equals true. So if the records are more than one, then for when to easily retrieve the information. Now here we need to edit over here as first of all, we have query. Then the result which we have. Now we need to convert into the JSON format. Okay? So just like that, SQL query select S trick from whatever table you want to extract the data. And doing the same thing here. This myapp is my table name and then query all. So if you're going to recoup all they increase which are there in our table. In case if you want to add some filters, you can also add filters into this two braces. Okay, now if we went to return the results and Atlas and we're going to convert it into the form of Jason phi. Okay? There's no need to actually use the system if phi plus till, it makes your reserve more. Justify. Hey, yeah, put it down some extra indentation. That's why we got some error. The problem. Now it can reformat this file. Now let us read on this application lash order. So here you can see that this is empty, Jason, okay? And this is empty because we didn't add any kind of content into our table, which will lead us into our next lesson. So hope you understand and how you can use get method to retrieve the information from your table. That's all. Dylan, keep learning, keep exploring and stay motivated, dear friends. 18. Flask Sqlachemy POST request: Hello, welcome back. So in my previous lesson, I have shown you that how you can create a matter for GET request. Now in this lesson we're going to create the mattered for post request. And also I'm going to show you that how you can use the postmen to test your APIs. Okay, so what is Postman? By the way, Watchmen is the complete API suit through which you can not only pull the APIs, but also you can test your API. It simplifies E-step of the API lifecycle and makes you better and faster APIs. So I think this is would be the best platform to test your PI. So I'm using it here, okay? Now here you need to mention the method which is the post method here. And yeah, that whatever requests which we're going to meet using postmaster, we're going to also attach the body. And inside the body, we're going to add the content which you want to add it into our database. So that country will be also in the form of JSON. Okay? So we're going to the fields of edges on the request suggestion into some variables. And then we're going to put it into our table, that table, okay? So this means that IQ, which is the variable we are going to contain all the fields of the Jason. And then we're going to particularly specify the field of disease and into the very evil. At last, we're going to insert this into our table. Okay? Hope you understand. Okay, Now let's write db dot session. Add this DB, The New Inquiry. This myapp is my table name and RID will be awarded ID than size would be sized, toppings will be toppings, and the cluster will request. The orange color is basically the fields of our table. And the white color. The other eye size which were written here, is basically the variable which you have created. Okay, now we're going to be added into our table. And at last we are going to commit it. Okay? So in this way, we are using this request method to put our adjacent materials into our table atlas and when to redirect to our this getMethod one. So that whenever going to post the data into our table, it will going to also retrieve the whatever data which we have added into our postman screen. This is our postmen. This is my workspace. You can create different colors, different collections here, and different request for APIs and store them into your collections. Okay. Now, first of all, I'm going to show you and how you can test your GET method. This is the URL slash order. This is HelloWorld, the base URL. Then we wouldn't put order. This is empty right now. I have already shown you into my web browser when we're testing that GET method, okay, now you need to use this URL again. And now we have changed the request method, do the post method to this body section, you need to add the Jason. Jason, we're going to actually add it into our table. Okay, so let's write down all the fields here. And all the foods, except the RID or in the type of the string datatype. So you need to mention, you need to keep this point in mind that whatever values you are going to insert over here should be in double-quotes. Here. Just write small here. Then you can use onion, okay? I'm just going to use onions topping here and cost. I'm going to use thin crust. Okay? So here you can see that I created a simple Jason and I'm going to request Jason with this post method. Here you can see that there is nothing store into our table. Now, you can see that we have successfully added the new increase into our table. And it is deflecting into the form of JSON format just because we are using Marshmallow here. Let me add another. Now here you can see that whenever we are using the post method, it is extra redact to the getMethod. That's why it is displaying at the bottom. Here. You have learned and how you can use the post method to add the new content into your tables. Okay, now in the next lesson, we're going to learn some more things about plaza skeletal K-means, some new STDP matters. Hope you understand how you can use the post method as well as the getMethod. So if you have any kind of doubt, you can ask me in the Q&A section or you can mail me or message me whatever way I will be happy to help you out. Okay, so that's all. They'll then keep learning, keep exploring and stay motivated. My dear friend. 19. Flask Sqlachemy DELETE request: Hello friends, welcome back. Now we have learned how to build a matter for GET and post requests, where we use the get method to retrieve the information from the database. And we have used post method to insert the new data into our database. Now this delete, the helper delete method. We're actually going to delete some data from our database. Okay, So without any further ado, let's get into it. So just like the previous matters here, you need to mention the method which is delete here, and the URL will be same. Okay? You need to change the name as well of your method. And here you need to specify that which order detail you want to delete. And here we have chosen our ID as a primary tree. So with the help of the primary key, which is already, we're going to delete that particular order. Okay, so our URL, we're going to pass a parameter. A parameter specifies which already we want to delete. That particular odd. Friday we're going to delete using our query. This query is my table name. It will look for this RID. At last it will going to delete it. So db dot session dot delete the entry which is selected for deletion Atlassian and recommit your transaction. So just write down db dot session dot commit, and that's all your job is done. So let me show you that how it works. At last we're going to return to actually are going to redirect to the get method. So while we were going to delete any method as any, RID, really actually see the current status of our table as well. So let me open the postmen district. It is working fine or not. So we have to not do others. Okay? And now we're going to open a new tab. And here you need to select the Delete option from here. And you all will be same. And you need to add the order ID. So here I'm going to delete or two. Okay? Now you can see that it is already retired, so we can now delete it again now and get met. You can see nothing's left because we have both the orders. Okay? Now let's create, again not a one. And here you can see we have order ID one again. So here this is a log. So what are the operations which we have performed? So we have deleted. We have used this delete two times to delete R1 and R2. Okay? That's all. This is how we have used delete requests to delete our details from the table. 20. Flask Sqlachemy PUT request: Hello friends, welcome back. In my previous lesson, we have talked at all about the getMethod post method and the delete method. So you might have family with a crowd acronym where C means create, read, update, and delete. So we have already covered the C part, which is created with the help of post method. We have created the bizarre order than r, which means read. We have used the get method to retrieve the Pizarro details. And then D, we miss this, you must still it is okay. D, which is delete. And we have used delete method to delete the pizza order. So here we're going to focus on you, you part, which is update. And we were going to use the put method to fulfill our task. And it is very important to you as well to understand this crowd operation because this is the for major operations which you must know. Because whenever we went to create any application, it can be web or Android or any other. If you are willing to integrate any database, you need to perform this crowd operations. So here, as we are focused on creating the web application using Flask and also to fill up the rest API with SQL Integration. So it's very important thing to understand how you can create the matter for this chord functionalities. Okay? So it will be C. It will look like the post method where we went to collect all the data from the request is Jason. And then we're going to we're going to update the values which is already there into a table. So here we're going to pass the parameter. And if you look for that parameter, if it is not present in our table, then we're going to throw an error. But if it is present, then it will going to update the value with the new variables, new values, which we have provided into our Jason. Okay? And at last we're going to just commit this new inquiry. And that's all your job is done. That the put method is required to just update the precipitates. Okay. I'm going to remove this new entry because it is not required as we have already that particular entry present into our table, the only thing is to update the things. Okay, so we did our task and at last just db dot session dot add and David of Session commit that sought. And again, we're going to redirect to over get order matter. I have written in my application. And here we have only one tail. Now here we're going to change things into this, this order. So here I'm going to change the size to x large and toppings to sweetcorn. And let's send this PUT request and see that the chain is which we made is reflecting the R-naught. So we have send the request and then we're going to send this request, GET request. Now you can see the genius which we made using the put method is reflected into our table, into our order details. This is all about the format operations which we perform in this section. The create, read, update, and delete. Let me do one thing here. We're going to add comments and put all the matter and the ordered way. So first we're going to have create and underneath, we're going to put this post method, okay? And then we're going to have the odd part which is read, okay? You didn't miss some part. That's okay. Now we're going to copy this and put it over here. I'm going to change it to read. Okay, and then we went to have update and delete. Now I'm going to reformat this foil. So all the extra thing will be removed and it will be in the more organized way. So now we have this four major operations, the crowd operations. Hope you understand if you have any kind of doubt, you can ask me in the Q&A section. Till then, keep learning, keep exploring and stay motivated. My friend.