Swagger documentation for REST API . Django rest framework project tutorial6]

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
or against welcome back to our tutorial series up to this point we've worked on endpoints to verify a user's email to register a user so now I want us to have the struggle documentation just so we can always see what exactly we're building in the backend so we're going to use this mode you could DRF yes ik or ysg however you want to read it so this actually gives us a way to accommodate yes it actually gives us two ways so we can use straw guy you I and guess you can actually come in and read more about what's possible with with the API but I'm gonna show you how to set it up on how to use it but of course there will always be more in the documentation so yeah that's that you can easily do con saga you I will use so again this one because I think it looks cool ah alright so let's install the package so this is gonna be deep install package name so once we have that we need to add it to install apps so now you know settings @py which is right here we need to come in here and also add it good so once that's done now they give us an example of how to actually set up the URL so for the URLs for the documentation so I'm gonna shall copy everything here then so you can have somewhere to start from so in the main application URL routing we're gonna bring them in here so keep the inputs for now then you see they define a scheme of you then they did they use this schema get schema view function and then it takes in this configuration so the title you can call it like income expenses API v1 is okay this description is okay then you define your terms of policy so I'm going to change this one to app upload clone then this can be add expenses okay but it can be anything your company name your whatever so now that you have that so you configure it that way and after that now we need to configure our URL so I'm gonna copy this one out you actually bring it in gonna copy everything here and I will delete this so down here I'll bring them in and then I will stop the URL path so I'm going to remove this regex stuff so I only want to keep this whatta you why so I am as well remove this but take some time to look at how the red oak red oak box actually make your printing so you can look at it why not alright so let's keep freed up and then saga so I can remove this remove this let's do this then I'm going to remove the first one so we can have the swivel pink and in the red oak link but I want this one got to be on the main application landing page so save that now if we come back run our application again run Java and sits back so when I click on the link hmm yeah so this one is not actually coming through so let's see why that could be the case so I'm gonna oh oh there's an issue so we actually doing this in a wrong file server today so we need to have this configuration in our main application routing file so in this yours at py this way I want to have this so bring it in there and then I will have to bring in or leave it for our configuration so cut it from here and then make sure you have it here let's bring in our inputs just bring in our inputs up to here okay so that imports everything we had already configured the URL paths so if we come back to the app and reload here you can see that yeah we have income expenses FBI looking good looking good so even here you can actually try it out with the registration just actually it secured taking them yes you can see that there is a gets created we get the results we try to use you that already existed see we get the Harold's correctly looking good looking good but now what I want to show you is on the endpoint to verify the email you can see that there is nothing nothing to help us to verify the email from this documentation so actually I post the testing of the other video just so I could show it to you here so for not to be able to do that we need to have inside your exterior is a class that exposes some fields to the view so so the way it works is we are going to need to create a series a class so here in our authentication serializes I'm going to have a verification sterilizer so class you may verification verification Surya Raisa this is gonna be inheriting from Syria raises modest area Raisa and then we want to define token field because we want the user to be able to see that there is a token needed on the documentation so here this is going to be three races though checkered now we can give Akey max length you like 25 five those tokens alright so you can define a maxing for the token then we need to define a class meta so link this one to the user mother cool user and then when it comes to the fields this is what we will want to expose so here you can do fields will be only they took and for now all right so once we have this now we need to import it cause in the deuce used @py we need to here set up a sterilizer class three Eliza understood class this is gonna be equal to that let's make sure we import it here and say so once we have this and come back and reload here and click there you can see that still there isn't there isn't a lot so we can see basically like what gets sent back but there is nowhere to send it so you already know that we are go it's going to be it's going to need us to send in the the parameters so somewhere like here so we need to add a word for user to be able to add those custom parameters alright so for us to do that go back to view study Y so first thing we are going to need to import from API upm so since it's going to be a special case and not like generic lately other ones so we are going to input an API view from from restomod so actually yeah we're gonna put views okay so here we continues with API view and now once we have this this can give us access to to add those things but we still need to do some mods some more customization right here on this method we need to tell swagger which which fields it should create here so for us to be able to do that I'm going to import something so from DRF it's called the areas to choose import something called swagger Auto schema all right so once we import that right here on our method we need to decorate this one with swagger Auto schema and then you can see that we specify some options in this so one option are going to specify is going to be money of parameters and this is gonna be actually so this is already list so you can supply different things so here we need to specify a parameter we get configuration so here I can put something like token Aram config and define this here gonna be talking param config so this is gonna be equal to so this we need to also bring in open API because this had to be before in the open API standard so yeah so from that's one input open API so it's composable config using open API so you can do open API and then we need to pass in open API good parameter and now the parameter we need to give a name which the name will be talking and then the next thing is gonna be where we want it to be so here we can have an in so in will be equal to open API in query okay but you can see all options at the possible so we also need we can give it a description so users can know what it's about the description and then we define a type yeah can add type equals you can also use open API to access the types that are variable then this is going to be a type string so now that we are wrapping our decorator here we have defined it there now we can come back I said now the application is back on the endpoint when I click there you can see that now we have somewhere to enter the token so if I pick try it out we should be able to see that we can now enter something and then click execute so notice that's when I submit something that's not a variable and click execute we get invited token but let's try to use our token here so I'm gonna come and copy this and back here supply a correct one then click execute so you can select it expired but let's try to create a new user so down here I'm going to use this email this in 100 gmail.com then the user name can be the sender and it was like that so notice that the first case were able to know that the token is is invalid and now saying us that it's expired so now we need this for the Canela case where the token is using is valid so a user that actually I know exists tidal estuary email same username same password then I'll click execute follow this user exists so let me actually clear out some of these users so down here we can enter Bay Python share so you can interact with the database monitored py Python when I did go share now we can import the model from authentication dot mother's boots user now you can do some type user objects delete all of them let's think there should be objects not object okay so that's these nine users so I'm gonna quit this run back the application run back the application and now just try again click execute so it's going to now go ahead ok so now you can see that you get it 2:01 and now when I go back to my email now you can see that I have a new email and then it has a token so I'm gonna copy they took em real quick copy it I'm gonna copy they took in real quick so I'm going to go to our API here you load it and then I'm going to go to email verify and now that we've set up a field I can outpaced our token here so when I click execute look at what happens because it's now the is a successfully activated alright so looking good so for us to verify that the user is activated actually we can come in here to our share gonna cut this one out then I'm gonna do a Python money literature so you understand that at first in our models when we create a user is verified is always post as the default value so let's try to query for this user so here you can do from potent occasion with mother's input user so once we have the user now we can do user put objects get want to get by email so you can do email equals so my email is just the one I just used to sign up Gmail go to Chrome and then we want the is verified key so you can do that is verified so now you can see that is true meaning that you are able to verify this user and now in the next one we'll go ahead and drop them in will go ahead and rock them in into the application so if you enjoyed the video give it give it a thumbs up subscribe to the channel so you can keep in the loop as we build more cool stuff I'll see you guys in the next one
Info
Channel: Cryce Truly
Views: 40,273
Rating: undefined out of 5
Keywords:
Id: XOB-aHKu6e4
Channel Id: undefined
Length: 14min 19sec (859 seconds)
Published: Fri Jun 19 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.