API Documentation using Swagger UI/REDOC. Django Rest Framework API Project Tutorial [5]

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey what's up guys in this video we are going to go ahead and tip and basically documents our API so as you may know previously we've built our API will have authentication up grab the credit for contacts up so now we want to be able to to document it so now if we have come dragged yeah and try to get at least you see we get IDs but then how do we expose this to the outside world for example if we have any developer on our team how do we make it easier for them to on board and our code base of course if they are gonna confront it they won't even need to know anything about our code base but they want the documentation they say show me the documentation so let's create a documentation for them alright so here we are going to be using something called how do they even pronounce this it's cold oh my goodness there's code yes the array of guessing so basically what this is gonna do it's gonna allow us to easily create the documentation so right here we are going to start by installing it so copy that so you know basically here you keep and install that one okay so as installs let's keep looking at these tips that they are giving us so we need to add it to our to basically our settings @py in the installed apps so let's do just that settings dot P Y which is here just add it alright so once you have it what is - what are they saying so they're actually giving us an example of how to approach this so right here I recommend you guys like come and check out this documentation and learn more from it learn more about the difference between legs so the UI and then the redock documentation but what this does is it actually gives us two ways to to look at our data so it has this redock documentation and loose with this weather UI documentation so i'm gonna copy this so we start from it so in the URL that py which is here just before okay let me bring this one to me run this our beginning and then bring this one up alright so this first screen is up a bit so inputting permissions we are putting the view so this is that this get schema view basically is the one that will be responsible to bootstrap or documentation so it takes in a configuration back you see the energy tells us what we'll be seeing in the the documentation so here we import the get scheme of view function so what it does is it takes in this configuration for the info so here we can define the quantity of our documentation we say contact list yeah in the default version v1 is okay the description can say an API what API is API great so an API for the okay the next four contacts let's keep it simple the Terms of Service is can be you company terms so yeah you need to define a contact so now it can be contact at contacts cause really the contacts application good local have to read us be remote but remote then you specify your license so this can be any depending on your company policies so it's public yes permissions allow any yes we want our front-end devs to view it any way and be able to access stuff so here now we need to go to like write these these URLs I'm gonna pop it is when I'm gonna delete this ash I'm gonna delete everything you bring that in here I said did it what copy and leave so now we basically are going to have putts so this is your name URL to used parts because yours is older school so but now we won't want to be basically the one that we work with mainly is this one with saga UI so much are going to a minute we they were the first one so now we remain with Sakai why I wanted to go to the home so we can keep the default route of the application to cut the documentation and so guys okay so they also provided us an option to use reduc sorry dope is also write saga so let's also keep it and see how it looks you might actually you might actually find that it's also as nice a swagger that's why swagger has some swag I believe I'd be the Spice Girls fun but it's anyway I'm just kidding I said cool it's a cool tool anyway so now we have the setup here so if we go back to our application what you're going to open now in the browser if I click there look at that look at that we have the documentation set up so right now one of the things anyway so we have the recommendation set up just by adding this configuration so right now let's go ahead and fix the problem that's around and then we see how to to finalize with it so if a sting is going to be that here on the author is it's not using like JWT it's not using GWT so first configure it to use GWT we are going to hop over to our settings that py file which is here so anyway in the in the fire we are going to define store the settings so swagger underscore settings so in here now this is gonna be a dictionary so here we need to define a security definitions so now it's called security underscore technicians so now this is gonna be dictionary and basically now we need to specify the authentication details so in our case it's gonna be an auth token so we can write both token and now we can even give an example so we expect it to be something like para and then the token so I can do like charity parity the routine huh anyway so yes make this one yeah that's so they know that they should supply Bearer and then GWT so then we need to define a config for this so basically what we want the type is gonna be API key type this token is gonna be Pik make sure you don't change this cause it's gonna yell at you so net then we're going to be looking in the authorization so name is going to be authorization and then we are going to be looking for it in headers so here you need supply and in key and then header alright so once we have this now we can go ahead and test it out again so let me reload rerun okay come back here we load it yeah it's app is showing then if you could authorize you see we are supposed to apply a GWT token so let's first try to test it out and see other things we need to do to work on so the first end point is register so if you look at it you can actually see that we have everything we need we have our model described so if you go to our tryout section and actually try it out so click execute you see that it sits now violating the password so this add a password that's is strong okay that's more so now if we do that you can start to get it on meaning it's created but let's test out our login good to log in and click try it out you can see that oh my god there is no way to try it out if you click execute you're telling us invalid credentials even when they didn't give us a chance to to be able to submit our details so the way we solve that is when it set up a Sierra is a basically for the login so here in authentication it should be here so in series at py we are going to set up another cigarette assault class gonna call it log in sorry Eliza this is going in health from posterior rises Tata Motors area Raisa and then here we need to define what should be visible actually in being this webpage Y so it's gonna be the password in the username so I'm not sure going to copy something here so password that but we'll be able to give them like what we expect off the password we need it to be at least eight we need it to be max 65 then I think is gonna be the username so it's also get it up to here so me rename these to be username and now it's gonna be a chat field mm-hm that's right so the minimum two is okay mmm-hmm so let's define a class meter and now here we can find our model and then our fields so now now of course it's going to be username and password all right so once we have this now we need to set it up with our view so in the views that py make sure you import it you can here and now here mix it up severe Isaac classes so you raise a class lots classes this is going to be equal to log in Surrey Eliza all right so let's take a look at here this is yelling already okay but this looks good so save it's gonna reload then come on reload here and now if we go to the login you doesn't let you have our description so meaning the syriza has a nice job it has told the view what is what to do in and now here we can basically work with like try to login so if we try logging in because he invited credentials so let's try creating an account okay so this create a new user so user to password will be two two two then the user name has to be unique to execute get the user returned so if we try to login with these details so like here so like here let's keep username and password let's try to login execute see you get a token good so now if we go to our contacts endpoints so they may actually called ups this good contacts and we try trying it and then we try executing you see that we didn't provide authentication credentials so we can't do nothing so now for us to be able to do something you need to come to the login and then like we say we pass barren space and then the token keep authorize and this is given truth to the user signing in so now if they try execute again you see that they get their responses all right good so if we try to post to this may actually do that so if we try to add to this go to try it out so let's not provide the contact picture because we don't have it so let's say observer it is false and then the count record is 3 3 with zero don't know which counted Aires comments in the comments with your country code I will do I will comment with my infest anyway so the name is gonna be test user then the phone number can be like 6 9 problem if we try execute you see you get the - oh good let's change it click execute get another one so now if we go back to our gate which is here and execute see you get our - good Rick all right so now yeah so now that we have that basic I you might notice that we are not getting the ID here so for us to be able to change the ID call this can be important that we send it if you go to our serializer contacts erisa so here you can put a comma and then add an ID ok so if you come back and we execute you see we get the ID back good so now if you want to be like a contact detail we can use this ID cause you're all set up the lookup field so now we know this user has three and four at least so now if you go to get ID you can pass you go try it out we can pass like four and then click execute and then you see we get the one so if want to update it this actually can help us do everything we want to do it like everything in the world including cleaning your room and of course no anyway so you can see it's really robust it's really less setup and it's amazing in the end so so thanks guys for watching give the video a thumbs up subscribe to the channel for new videos just like this one I'll see you guys in the next one thanks for watching and bye
Info
Channel: Cryce Truly
Views: 14,702
Rating: undefined out of 5
Keywords:
Id: xlcYLlndqz4
Channel Id: undefined
Length: 15min 18sec (918 seconds)
Published: Fri Jun 12 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.