Learn Rest API Testing Fundamentals with real time Examples in 75Minutes

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome guys this is your instructor rahul shetty in this video we're gonna see the basics of api testing so we will start from scratch to understand what is api and then i will give you some real time examples of apis so that way you will understand what are they why do we require them and how do actually api looks like right so once you understand the basic theory of api i will go over the core concepts of api like get post put delete there are some http cred operations which are frequently used in api testing we will go over all these and more importantly i will also explain what are parameters and what are different parameters present for api and what are headers cookies and their scope so with this you will get a theory knowledge on core concepts of api testing right so once you get a theory knowledge then i will introduce a tool called postman to show how to test the apis so here we will understand the apis and their operations once you understand them then we will start testing those apis using the postman tool and for that i will take one real life example google maps api to demonstrate this api testing process using postman tool okay so we will go over all the google api like add place apis and show you how it works all right let's get started so let's start with the first basic definition of an api so instead of knowing what is an api first we should try to understand where do we require this api in the project architecture what is api is a simple definition api stands for application programming interface but did you understand anything from that no so you have to practically understand where exactly this comes into picture in end-to-end project architecture i will try to explain those and then i will come back to read the api definition again so that you will have clear understanding of what exactly api is okay so i will tell you one problem now let's discuss this scenario and from these scenarios we will try to understand what are the design issues and what are the problems and then in the next lecture let's understand how come api addresses these problems okay first let me take one website for example marriott hotels so these are the hotels which provide reservation services and they have their room servicing hotels in everywhere across the world so they have prepared their front-end website which looks like this where you can come here and select your city and then you can see if there are any rooms available and you can book it okay so that's the front end and let's assume that this whole website is prepared long ago at least 10 years ago and they have using java as a language to design this front end like java html css okay next coming to back end so in every project there will be client and server client is nothing but what you see on the screen okay so all the ui front end we call it as a client and server is nothing but what it gets stores from your client now let's say when you book a reservation from this website then all your details reservation number at what time you are booked everything will be stored in the server side which we also say as a packet they do have some databases or some backend code which process your details and generate reservation number okay so let's assume that the backend code is also developed in java so create reservation is one method just a scenario assume that there is one method in the backend code so that will actually responsible to confirm whether the rooms are available and it should create reservation okay once the reservation is created that id is sent to database and it gets stores here so that tomorrow when you want to retrieve your existing reservation you can use this database to get it back to your client okay but ultimately this method will take all the check-in date and checkout date in the passenger name and it will check if there is an availability in that particular city and then it creates the reservation and pass the id so that's the overall concept and this is how this mario website works now you all know that not only that specific website there are different other marketplaces where they can sell hotel rooms like hotels.com booking.com and makemytrip.com there are different websites which also does the same basically these guys collect all the hotel information across the world and they display in their website so in that website also they are showing this marriot hotel what we originally saw this is their official website but you can also book this hotel from hotels.com or any other website now problem is end is now client is nothing but hotels.com so this is a client right and now hotels.com reached madrid guys they want to showcase their hotel in this hotels.com website but how come you can form the integration is the question so let's say now um you have to book a hotel in alabama state and you will give check in and check out and use a check availability so hotels.com do not have any information about this hotel right marriott so they have to contact marriott back end and see in their database if there are any rooms left on that specific date so once it returns those details again it has hotels.com should retrieve from bracken and it should display for the client here that two rooms left or three rooms left but how can hotels.com website can talk to marriott marriott hotel will not expose their code right so let's see here create reservation is a method which is actually doing us all the work but in this case it's possible because front end and back end both belongs to marriott so they have written one project where each and every file talk to other file and get the data this is fine because it's their whole code and all these code is sitting in one repository okay but hotels.com is entirely another repository and why do marriott hotel exposes their complete code okay that's very bad thing right just because those guys market our rooms that doesn't mean that we will hand over complete our repository code okay that in that case how do these guys get the information from marriott or when someone books the reservation here how they will pass that information here okay so when you book any hotel here directly hotels.com will not confirm you all the details whatever you want here should be sent to the marriot backend code and that marriot back end will validate all the stuff whether availability and all and then it create reservation and stores the id and give it back to the hotels.com but how this website can talk to this code that is our problem because both are different repositories maintained by different companies and like hotels.com there are hundreds of websites which also does the same like make my trip yatra.com or booking.com hotels.com so will marriott give their repository to each and every guy who ever ask that's not the ideal thing right then how it is happening in our day-to-day life i think you are slowly understanding why api is required okay this is our problem i'm just telling you the problem now unnoticingly something will strike in your mind that we need something to fix this which is nothing but api so let me give you another problem before we see and bring the api into the picture all right so marriott only both front end and back end same repository when they developed 10 years ago they used java and jsl language to build all the front end but recently you know there are many front-end frameworks like angular react vue.js so they want to update their web page with the latest frameworks available which is let's say angular so you all know that angular uses typescript okay it will not use java so these guys have written typescript code and developed front-end and again there is a problem back-end is written in java okay so we are very sure that no other tool can beat in back-end code other than java in front end you have so many languages but backend the best and ever green is java but when you write code in type script and can you call this create reservation method which is written in java into typescript it's not possible right not only java and typescript you cannot call a method which is present in python language into your java technically it's not possible so earlier our life is easy because everything is on java but because of the market competition they want to develop at top notch websites with good look and feel so they have adopted angular type script the one solution is that they have to write entire back end now in typescript which is really hectic and not at all suggestable because typescript is very popular in front end but not at all in backend okay this is very very common in recent days i think each and every website know what you see in your real life front end which is client will have one stack like angular type script in the back end when you go you will have another stack like java these are the design problems which will industry face when you don't have an api but still you don't know how api solved this problem you understood that there is a problem and obviously as this course is on api testing you will be knowing that api is going to solve this problem but how so in the next lecture let's see how come api play a major role in solving all these design problems and from there we will see the definition okay thank you welcome back so now let's see the solution to fix this problem when you have different stack in both front end and back end right so now we were bringing a feature called api which actually acts as an interface between your client and the server we also call it as a middle tire layer between your client and server so how does this help us so basically you know that create reservation is one method somewhere are present in the backend code which will actually check the availability and create reservation and send store certain database there could be 100 lines of code inside it it doesn't matter so what we will do is that we create one api so that api will call this create reservation method whenever somebody hits this api so this api we will host in the same server of mario.com so if somebody try to access this api then this api will come and call this create reservation method okay that's the baseline so now what is exactly difference of calling why can't we call directly so this api is independent of any language now let me go back to mario.com so you will give the destination dates and your name and you will book your ticket so from front end when you pass the destination dates and the room what you want these are the details you basically need to reserve the room right all these details when you click on reserve button at the end once you complete the flow and finally you will click on the reserve button right basically front end will capture all these values destination rooms dates everything and front end captures this data and send it to the api so whenever it is sending to api it sends the information over http protocol http protocol is independent of any language okay so either you use java javascript or typescript no matter what language you use the all the information from front end it will send to the api using http request okay once this api gets the details all the details it will send to create reservation because create reservation here requires first name check-in date checkout date area where they need to book and the number of rooms or something like that it needs those details to run this method and create reservation so if you go back to our first screen initially both are in java so directly this front end is interacting and calling this create reservation with these values whenever user enters in the client side all the details are successfully captured by this front end and those details were sent as an input to create reservation method based upon these details insert processing will occur finally reservation will get created as now it is in typescript what we are doing is that we were sending all the information to api and that information is going on http protocol and moreover when you send information you are sending it in one format that format could be either json or xml okay so xml here is again independent of any language right both json or xml does not belongs to any specific language family they were like used by every language now javascript have libraries to parse the json or xml java have the libraries python have the libraries so these are like representation okay these are not languages right these are representation of data in specific format so however all the details like first name last name you will send on json over http protocol to api and this api now give those details to create reservation so developer have to create this api in such a way that when someone hits this api automatically this api should capture that information and send it to the create reservation method so that's the api duty so developer will create the api in such a way that it does that work how to create api is not our scope okay it's we are this course is only on testing so you don't worry about it you just need to ask developer that do we have any api to create reservation okay and then it will send back the response to api if it is success and the same response the api receives it and then uses xml or json to send back that response to front-end so front-end tools like angular or javascript will pass that json as i told you json can be passed by every language once they get response back like reservation number confirmation yes or no they will send it back in a response of json and angular will type script will pass that json and extract the values and it will show on a front-end html to the user that your reservation is confirmed and this is the reservation number so in that way there is no interaction with angular and java here what all this create reservation is required everything we were getting as from an api and whatever we need to send it to create reservation everything we are sending it to api so this api acts as a middle layer or an interface between client and server and serve both the technologies and tomorrow let me show you another screen there is one more problem that hotels.com right now hotels.com want to showcase marriott hotels in their website initially we thought it's not even possible to share all the back-end code so now this marriot hotel guy can expose their api because this api do not have anything right there is no code inside it what all it does is whenever it receives request that information it will pass to create reservation that's it but so both are hosted in the servers right once somebody hit the server that information will be sent to the create reservation server and backend will be happen in marriott server only and the id will be send it back to api and api will give back to the hotels.com so there is no interaction between hotels.com and marriott hotel directly now so even hotels.com do not need any code now they just need to confirm reservation so these guys should expose an api like this if they expose an api then um these hotels.com will access that api and it sends all the information like first name last name checking date checkout and then does the same thing just like how we have done in this scenario nothing different it's all about exposing an api okay so this is how we gonna solve our problem and if i go back to now wikipedia definition of what is api it is an interface full form is an application programming interface it's an interface a communication protocol between client and server intended to simplify the building of client-side software that's what we saw now right basically it's acting as an interface or communication protocol between our client and the server to simplify the building so to simplify the design process okay earlier now if there is no api like this for typescript and java it's tight to integrate so they have to change the whole architecture so for all this simplification without complicating the things this api is playing a key role between client and server as a communication protocol and solving our problem so that's the overall concept of what is api and where do we require api in real time okay so let's continue in our next lecture thank you okay so when i say api there are different ways to create these apis there are some set of standards we need to follow to create this api which developer does that so the most common apis where everyone uses are rest apis rest possess some rules and regulations in creating an api so that everyone needs to follow those criteria to fall under rest umbrella similarly there are apis called soap apis we also say them as soap web services services or api these terms can be interchangeable there is a slight difference but in general people call apis or services as a same name okay and soap services uses a different standard in defining that soap services most of the legacy services are relied on soap because the rest is the one recently into market a few years ago but soap services are in existence from ages the problem here is that soap have so many conditions so many restrictions and that's the that provides tight authorization authentication as well to communicate with api even rest does same but rest we call it as a lightweight protocol and now majority of web applications are moving to rest apis only because of its lightweight and flexible way of coding okay and this course is entirely focused on rest apis any latest website which is being developed are being on rest apis only the legacy services which are in existence from years are still on soap services but all the latest technologies like facebook google instagram every other website uses rest apis only because it's easy to build and maintain okay that's the main reason and rest api testing is very very necessary because now for hotels.com guy he needs to know whether he is getting the actual result from marriott api or not okay so that's not possible to talk to create reservation method because that is external third party code right what all he can do is test the merit api to see if he is getting the proper response whenever marriott hotel is sending back if something is wrong in this api then obviously that wrong details will be sent back to the customer after he booked the ticket and if someone is not thoroughly testing this api and that's it and they might get random number or they may not see the reservation correctly and there will be so many problems okay there are people who can test this back-end technology in marriott company and there are people who test this front-end part to see if everything in the ui is working fine but if you don't test this integration part of how you are getting the data then you know you might end up with so much of major bugs in your application so that's the reason these days testing an api is becoming the hottest requirement apis are just on a lighter weight you just need to hit an end point and you will get the response within a second you will be able to tell if marriott apis are working as expected or not okay and before we start with one example we need to understand some terminologies as part of this rest apis okay so as i said rest is one of the architectural design to create apis these are some of the rules which you have to follow step one is end point what is endpoint or we can also say it as a base url so this is the place where your api is hosted and now if you want to hit this api you actually need to hit that end point so end point is that area where your api will lie your api will seated there and someone asked you to hit that api which is nothing but hit that end point hit that base ura where exactly that server is located so if you want to test any api first requirement what you need to have is an end point that means where exactly that api is located so that you can call that api by hitting that end point from your api testing tools step one don't worry again as i stole when i start doing one example i will clearly explain what is the end point where to give it how to hit it how to get the response everything you learn in detail i'm just giving you high level overview before we start and next we all know that information is being sent to api on http protocol right there are different methods which http exposes when you are communicating with these rest apis from your client so one of the method is get method post put and delete these are the four commonly used methods to communicate with the rest apis so here when you talk to api you can talk with get http method or post or delete or put so let's try to understand on high level each and every http method now so that in our next lecture when we start taking real time examples we will do some examples on all these http methods right get method so this method will be used whenever you want to retrieve some information from your server now let's say you want to retrieve existing reservation for that also marriott guy have to come up with one api which will give the reservation details when hotels.com passes reservation id so basically from front end in existing reservation if you go back to your existing reservation you will give that your id right and you will click on retrieve so that id is being sent to get reservation api which mariot should expose okay that api it captures and then it will send to appropriate method and that method will be responsible to get all the details from database for that specific reservation id and it will send back to your api and api again will send it back to your front end in json with all the details once front end receives that json with all the details they will read the details and display on the screen that is how when you try to retrieve any reservation process happens in the back end so here get http method should be used to call an api when you want to retrieve something from their server if that is your requirement then this marriot guy has to develop api in such a way that that api will accept only get http method so that's the rule you might think that why can't i use post you can use it there are four different methods given by rest api but as i said when you are using rest architecture you need to follow some specific rules so it's not for us developer has to prepare like this i'm just showing that okay why i am teaching you is because tomorrow when i am explaining you to hit this api by using get method you should not confuse that why should i use only get because the developer will create that api by accepting get method only when you want to extract from information from the server so that's what i clearly given here okay before i come to this how to send data let me talk about post now when to use post post request is used to send data to server now if you are booking new reservation that means you are giving new details of the customer and his itinerary and it should create something reservation id right so basically we are creating something on our server with our details and the reservation so when you create something on the server then when you pass the details the api should be like post okay that's the rule to have as a post http method so when you want to create reservation then the api what they expose should be post and when you want to get reservation then you can use get next put put will replace the existing resources which are already present on the server basically you have created one reservation using post api done thereafter you have to update your reservation by changing last name or phone number whatever so in that case this api marriot guys has to provide one more api to hotels.com and that api should be like update reservation okay but when they create that api the goal of that api is to update some information present in their server right in that case this has to be accepted by only put http method okay so that when you call this api method while doing api testing you will clearly say that i am going to use put http to send my information where to give all these i will explain there is a tool what we start with the postman in the postman i will clearly explain how to give http methods like get post put and the final one is delete we also say them as current operations when i say crud operation c for create post offer retrieve get u for update put d for delete so we often call them as a cred operations on your api all right so these basics are enough for us to start with our actual api testing in our next lecture i am going to show one tool called postman which will help us to do this api testing and there we will see all these operations again end point so basically to test api what all details we need we will discuss first and then we will hit our api and then start from there all right thank you so one final lecture before we wrap up all the theoretical discussion on this rest apis so from very next lecture we will dig into the real time examples and i promise thereafter no theoretical everything practical will be done from next lecture because you know you need to understand some theory before you start seeing how to test api so that's the only intention and this is the last lecture let us try to understand few more concepts here first what are resources so resources basically represent an api or a collection you know which can be accessed from the server now for example google.com is the server that is the place where all your apis are stored now this is the base url in the last lecture we learned what is base url right that is the place where your apis are hosted right now in google there are different apis there are google maps google search google images and google docs so there are different sections right and for each section there will be an api now once you reach that server to which api you have to redirect so that information will be given by resource so in this url this is the resource okay so this maps resource will help you to tie up to the maps api so whenever developer design an api he will create a resource name to that api okay so that resource name we will include in our base url so that when we are sending the request we will pass that resource name so that google knows to which api it has to direct the request what it received to its server so every api test you do should have a with a resource and base url these are mandatory okay without these details you cannot send any request to api server okay so in these examples maps is a resource search is a resource and images is the resource all right next when you send a request we just realized that we need to send these details as mandatory right there are few more details which are optional and depends upon how that api is designed if that api is expecting parameters you should also send parameters as part of your request so there are two type of parameters we have when calling api server one is path parameter and another one is query parameter so let's try to understand difference between these two path parameters are variable parts which keep on change for every api request they are typically used to point specific resource within a collection so that means it's like a sub resource images is a collection where we are hitting the end point in that images you are interested to retrieve the image with this id okay when you upload an image in google obviously for every image it will have some unique id so that you can recognize that right so that's nothing but path parameter to point to specific resource within collection now in amazon you might make some 100 orders so amazon.com orders orders is a resource here okay so there is an api which have a collection of all orders so when you call that api you are asking that i need only the response with one tool order so this is a parameter so you are sending a sub resource as well so that amazon response will be drill down to that specific order and you get a response okay so that's the path parameter and similarly in the cm fashion we would send another parameter when you are sending an api request that is a query parameter query parameters is used to sort or filter the resources amazon.com this is the base url and this is the resource right now i want to sort the orders uh based upon this date so that it will give me the details only on orders placed on the state unlike path parameter we are not finding any sub resource here okay in path parameters from orders you are drilling down to another sub resource but whereas in query parameters when we use them it's like filtering or sorting or drilling down into the existing resource only we are not re-routing to any sub resource here okay so that's the difference and how to differentiate between path and query okay when you send if it is a query parameter you should have a question mark before writing the parameter name and this is parameter value if it is path parameter it would be just like url only you will just add one more slash after resource and you will pass the path parameter let me show one simple example where query parameters are used let me go and search new york in google search so let's see what happens now copy the url what got generated when you search with the new york and i have pasted the same here as well right so this is the url let me copy it again so here this is an base url so that means we are hitting the google server in their server resource what we are accessing is search so that's why you see that slash search this is the resource name and next you have parameters here and if you carefully observe it starts with question mark so when it starts with question mark then that kind of parameters are called query parameters as i told you that query parameters are always identified with question mark if there is a slash then they are path parameters so basically in their search api we are drilling down the results that means we are filtering the results with new york search keyword okay similarly there are other query parameters as well so each and every query parameter is separated by amp percentile but when you start query parameter for the first time you should always give question mark right so this is how your request is being created and sent to server so that now api understands that these are query parameters and this is resource name and this is base url based upon that it will redirect your request to the correct api and gives you back the response based upon the parameters what you send okay so here we send new york related parameters so this is the response okay once we get the response from api then front end developers will read that response and generated html page for us like this okay so what you are seeing is now front end code but all this front-end data is generated from the response what this api gave us okay so this is how we will test and see the response all right this is the best example to understand the difference between query parameters and path parameters when you are doing real time examples from very next lecture you will again understand in what scenario we have to use path parameters and what scenario we have to use query parameters and everything will be detailedly explained from scratch you need not worry all right so overall when the end point is constructed and when you are calling an api with the url this is how it looks one is a base url that is the server name where your request should go to and this is a resource to point out that specific api because google may have hundreds of servers right so which resource you need okay which api unit that decides based upon slash resource what you pass and then these are optional like if that api demands to have some query parameters to understand the request then you can send query the or you can send path this depends upon api contract how that got designed okay but these are like mandatory all right so this is how you ultimately build end point so from our next lecture when we design endpoint we will fill all these details and hit the api server to get the response okay i'll show that very soon now one last topic what are headers and cookies so these are also might play key role based upon how api is designed these are like metadata additional data which api needs to understand okay in layman terms it's simple that we were sending additional details to api to process our request okay so you want to hit and get the details from one api but that api is secured that you need to authorize or authenticate yourself so you would send user name and password to authenticate from headers or you would send login cookie so that api understand your request and give the response all right and when you are sending the request so api should know in what format you are sending the request you could send it in json xml or text html you have to tell to api that what kind of format your request is being sent so that details we will give in header like content type is json so these are like additional details we will send to our api right so now you might have questions where i should send this headers how i can construct covery parameters where i should pass all these details now we will start looking in our next lecture i will introduce a new tool called postman tool so this course completely teaches you api testing in both manual and with automated so for automated we use the rest issue but before we start automation first of all you should understand how to test an api manually thereafter you can replicate into an automation code with the way of how you have designed okay if i directly jump to automation you won't understand i have designed some bunch of apis for you guys to practice we will go through all of them and first we will test it through postman so for manual testing the commonly used tool across the world is postman so i will show what is postman and how to do testing using that and we will take it from there all right see you in the next lecture thank you welcome back right so let me download postman tool in this lecture so before i show the api what we gonna test first of all let's download this tool so you can just directly go to their official website postman.com and here you would just have this download the app button where you can simply download that tool into your mission okay so based upon the os you have you can download that respective version so right now i'm in windows 64 bit so i'm selecting that it's simple it downloads in dot exe file just double click on it and it will open the app like this so this is how you will see when you first open postman you won't see any projects on the left side because these are the projects i have used in my earlier trainings okay so we will freshly create new project here and start testing let me show you the api what i want to use in upcoming few videos to test and understand the api basics so you can download that api from this website rahulshettyacademy.com so navigate to practice projects tab and here you will see an api contract google maps so i have created this apis exclusively to practice for the people who have enrolled in this course okay so this is the replica of google map apis so i have gone through the google map apis and how they work so based upon that i created few apis which exactly looks like google maps and you know i hosted it on my server so that you can practice them freely without any cost so this is the one you can download this complete document from here there are four apis i have designed add api so this api will add new place into server i hope you all know about google maps and how it works so if you want to add a new place let's say you bought a shop and you started a new business basically and you want to add that place into server so google maps have provided one api where you can fill all the details and you need to just submit to that api and that api will automatically create place for you in the backend similarly there is another api called delete api so if you want to delete any place from the google maps which you have created earlier then you can use this delete api to delete the place from their maps server now if you want to retrieve any place now you can open the app and you will just search with some city name and you will get all the details all restaurants around that right so that's all happening with the help of get place api okay all is happening behind the screens you will just give the details but you don't know what happens right it's all about get place api which pulls up all the details and it will show up for you okay so there is one api which we need to test that as well and finally there is one more api called put place so if you want to update the place with the new details let's say you have already placed in the google server and you want to update it with new details then you will use put place api so if you remember in my introduction section i clearly told that there are four types of http methods are there to interact with api post get delete and put so i have made sure that i cover all the scenarios with this api example okay so we will not only discuss the single api by end of this course i think we have discussed around four to five different complete api projects so this is one of the project out of it okay more importantly when you are in a project and if you are expected to to do some api testing the first question what you need to ask is to get api contract so if someone asks you to start testing apis you just can't do it directly okay you need to know all the contract of that api so contract in the sense you need to know what is the base url what is the resource query parameters http method what is the json body how does it look like and what is the response you are expecting all the details should be given to you okay so based upon these details you will test the api and validate if that api is behaving as per expected criteria or not okay your developer should share all these details with you when they expect you to do some api testing if it is just a web browser testing you just need a web browser right okay so if you want to test rahulshettyacademy.com they can simply tell the url name and you can start testing this app but whereas in api to test you need a lot of things so we generally call that as an api contract okay so you should ask them first give me the api contract so that i will start api testing yes they have given and this is our api contract now let's begin manual testing using postman tool so let me open postman so first of all to create a new project in postman terms we would say a new collection right so collection name so this is our own api right which is hosted on rahul shitty academy so i would say rsa stands for our academy and then maps so this is our collection name you can give the description what all it does if you need and then create so this is like a folder name that's it under this folder now let us start with add place api you can say add request so now we are actually adding a request to send to the api what is that request name i would say it has add place and save it to rsa maps so that request now will be stored under this project awesome now double click on this request and here you go these are the details what postman is showing us now we have to fill all the details and we need to click on this send button so that your request is being submitted to the api with the details what you provide first things first base url so this is our base url so let's go to the postman and provide the here if you see enter request url so we need to give the complete end point here so i clearly told in the previous lecture that endpoint will be constructed with base url slash resource remember slash any parameters that's the whole syntax of the end point so after constructing the complete url we would call that as an endpoint but this is the base url where our server is located right slash you should get these details again do remember that someone has to provide all these details so there is clear information that we need to target this resource maps api place add json that resource should be concatenated with base url make sure there is only single slash good what next query parameters so if you see the standard syntax base url which we have given resource slash query parameters needs to be sent okay you can take this as an example okay just search in new york in the url and you will know how to construct this end point with the contract what we have we don't have any path parameters we just only have query parameters and they clearly given that key is the query parameter name and this is the value so you need to send this as a query parameter to access this ad api awesome right and if you remember i clearly told that for query parameters you should provide and start with question mark then only it recognizes that as a query parameter okay instead if you see here params if you there are different tabs present in postman so you can come to this tab and here it clearly told us a query parameter even if you give here that's fine it still will be concatenated let me show you so key is our parameter and qa click 1 2 3 is the value so this is our query parameter key value and you see that when you start providing here automatically here it got concatenated okay so either you can provide it here or you can if there are more than five to six query parameters you can list down all here step by step so that automatically it will construct on top so this is your complete request endpoint and next http method so what kind of method it is so in our introductory lectures we thought that get is to retrieve details and post is to submit something on the server so we are adding a place in an api so that means we are submitting some new details into the server so that's why developer have designed this api and given http method as post okay again you don't decide this they should tell you what is that apa nature okay so you cannot predict if if they designed it as an another http method then obviously you will run into issues so that's why contract is more important so http method is post so you can set that here right now by default when you create a new request in postman that will be defaulted to get so change the drop down to post awesome so these are the details we have given till now and what else and if you remember that for post request we have to send json body okay so this is the sample body you need to send now we are clearly telling that go and add a place but what place to add and you need to give lot of details right to add a place google will ask you a lot of questions so what is the location latitude longitude accuracy name phone number so if you give all these details then only it will create a place so as it is the post http method all these details should be sent securely in the body if it is a get request you can send all the details in the url itself either in form of query parameters or in form of path parameters you can ask everything in that url endpoint url only just because it is a post the details should be securely sent so you need to know what is that format of the json as well again these details also you should get from the person who developed this so let me copy this json body let's assume that this is what we got from them and you can change the details so this is like schema syntax you can have your own name on phone number address everything but format is this all right so there is a component called body here if you see you need to select it and our body format is json 99 times when you are dealing with rest apis the body will be json only now select raw as a radio button and then from the drop down select json place that entire json here all right so you can change any name so right now i would so this is my new organization which i established and this is my phone number everything okay and the category you can write as an education so let it be what you have right now here and website you can give the website name one more thing that it's better that you can also have a header so as you selected json as your input automatically in headers you see that content type is application slash json this header is automatically added because when you are sending the request we were sending the body in json response request right as you selected the json in headers also postman automatically set content type so content type is a header used to say what format you are using this is a standard header awesome so all the details we have successfully given as per the contract shared with us okay and this is the complete url you see that i have written here just make sure if everything is as expected so now you can submit this request to an api so that it reaches the server and goes to this maps resource and from this is the resource and from there it will read this request and give you the response back okay so as per documentation contract the response should be something like this if it success then the response fields should be like status okay and you will get one unique place id to recognize that place and if you want to use that place in the future again you can use this id to retrieve okay and there is one more id component as well and the reference and the scope these are some different values what it gives you back all right so let's submit this request awesome perfect you got the response you see that when you scroll down this is the response section and this is the request section so you have submitted the details and you got a response that okay so that means your place is now added into the google maps server but again this is dummy okay so that's added in rahul gt academy.com server we are not dealing with the real apis you have to pay to deal with real apis but there also exactly same thing will be used okay i just created a new apis which looks like this okay so you can verify if the response what you get is as per expected contract and the status 200 when the status says 200 that means it stands for successful http response what you got okay so this is how you can test api and see if it is giving the expected response so we have successfully tested one api by going through the contract okay in our next lecture we will use get place api we should be able to retrieve the details what we added using the get place api okay we'll talk about this in our next lecture thank you all right so let me show another api now so we are done with add before we see delete i will talk about get place api so this api will get existing place details from the server okay so basically when you create a place you will get one place id okay that is the unique for the place what you added so in the future if you want to refer to this place you can ask google maps with this id so that that can read reference right now the contract for get api is this is the base url which is obvious because it's hosted on our server this time resource is different if you observe for add place it is api slash place slash ad and here it is get so that means resource is different so that it will reroute to different api call this time when you provide this resource okay and parameters and this is interesting so if you see here this contract says that get api is expecting two parameters as an input one is a key okay key is always hard coded and it is qa click one two three okay so this is like accessing your api securely so in real time you will have your own key with your corporate account but here it's a hard coded so that doesn't mean that every api should have this parameter i just created this to say that we are using one parameter to call the api okay now next parameter is a tricky one place id okay so when you ask google to get that place details you just need to provide place id because that api should understand what place details i have to send it can give you only when you pass the id okay based upon that id it will search in their database and it will give you the all the details what the person initially added into the server okay and that's what we need to do and here http request method is used as a get because we are not submitting anything to server we are just retrieving the details okay i hope you got this information in our introductory lectures so as we are just retrieving from database we are using get request and when you use get there will not be any body okay body will come into picture only if it is not get okay if it is a get all the details what your api needs everything we will send as part of the url only okay so here these are query parameters okay so obviously we need to send all the details in the url and it's a get so obviously there is no body and when you hit you would get a response back with all the details of that place just like what you have added initially like likely to longitude name everything you will get back right so for add api these are the details we sent right now using get api in the response you should again expect same details okay so that's what contract says and for that you need to provide this place id awesome let's do that now so let me create another request um add request and then so when you are working in your real-time projects you will see their company url where that servers are hosted and the resource name which will identify that api uniquely and now we were asking about query parameters sorry why i am giving here let me wait this is like just get place i'm more excited to teach this get place so i'm giving before okay so here right and query parameters you can either give here or if there is a separate tab let's give it here key will be qa click one two three when you see you see that when you are typing here automatically it gets concatenated and next is place eddy is what this get is expecting right so that place id let's say you want to retrieve the details which you just added in the last lecture okay so this is the place id you got in the response so grab this place id and place it here perfect and this is get http call so you would use that and what else we need to give i think that's all because this is just a get and there isn't no body and let's hit this request and see what happens sending great you see that you got a response back with the details what you just added here in the add place so the same json here is replicated okay but there is a little different with the syntax but obviously that's how the api is designed but you see that all the details that our website is rahul cityacademy.com and the guy name is rahul shitty academy and everything is pre-populated so this is how you can retrieve the details using get place api so key point here is to pass the place id and this id will get when you create ad place for the first time in the response okay good so when you are asked to do manual testing you will first add the place capture the id and you will use the get place api and when you get a response you will make sure you validate the response what you have is what you initially sent in ad place okay so this is how basically you compare and more importantly you would see the status okay in the response if you see status as okay and it's the number is 200 that means it's a success okay nice so this is a get place and i will quickly show delete place add request and delete place save to rsa maps and let me go through the contract as i said contract is the heart for your api testing if you don't have these details how would you know what to test okay um there is a put here but first let's start with delete yeah so this api will delete the existing place so we have added this place right let us try to delete that okay i'll delete this place using this api and again i will try to call with get place api then obviously you should not get the response because you just deleted it and after you delete if you ask to get it again you should get some response saying that place not formed okay that's again testing so let's test this so contract base url resource and the resource this time is a delete perfect and query parameters key right next this complete request is on post obviously because you are now deleting place so that means you are submitting something into the server you are not just retrieving it you are making modifications either adding or deleting when you update something inside it is always suggested to go with post or delete okay so both these both will be used let me write a delete because i recently modified this api to delete but do remember that when you update or modify something post is a superset okay you can use post for any alter operations on your server you can still write delete because delete is exclusively talks about deleting something but that doesn't mean that post cannot be used here it's all depends upon your developer and team how would that api needs to be written okay earlier i have this as a post but just for explanation purpose i recently modified that to delete okay so again you will get that from contract don't worry you need not assume anything if you don't see that in contract just ask the team that what is the http request type for this api that's it they'll tell you all right so body as i told anything apart from get should go as part of body okay forget you can send it in the url you know that we were sending the body in the json so whenever you select this automatically hidden also will be added right and this is how you need to send your request select the body now which place you want to delete let's say that i want to delete the place which i just added where is that add place right yeah this is the place id for what we added now i am giving the same place id here so that when i submit this request it has to reach delete apis and then it has to pick this place id and it should get delete from the database okay let's see awesome the response what you got is status okay that is what we need here okay so that means that place is deleted the one what you added in the last lecture now should not exist in dracholshetti academy.com server okay now i will go to get place and if i hit this api again okay just before we saw how we got the response right now when i try again let's see what happens it should fail you see that get operation fail looks like place id does not exist because we just deleted it good so this way you tested how to add a place if it is working or not and get the place and also deleting the place all right in the next lecture i will show about put place api with that we can drop this manual discussion and i will quickly switch back to automation gear and show how to automate all these api testing validations okay thank you welcome back so let me quickly show how updating place works using put place api i will create one more new request and i would say update place right so by now you are familiar with how to create the complete url right so this is the contract for put place api so let me very quick write all the details update place and this is the resource name place slash update slash json you see that resource name is different for each and every api here okay so query parameters it says as a key is qa click one two three and then this is an http method put okay so i explained you in the introductory lectures that we use http method put when you want to update something okay when you want to add you will go with post but you can still use post here as i told you in the last lecture post is a superset you can use either post or put but in general document advice people ask you to it's the best practice to use put but i know so many companies which they rely on post on common for all these altering on database okay they will only rely on two api methods get or post for practice purpose i am showing you all different http methods so that whatever you have in your company you can work on it with the practice what you did here so put is a http method to handle this api as per contract what we have designed now so this api can update address okay so we have designed in such a way that it can update only the address field so updating all the fields became little bit complex while writing the code so i i have taken a sample of updating the address so whatever the address you have currently if you want to update that address then you can use this put place api and then you can just update that let's see so now i will go and add a new place because i just deleted in our previous lecture for demonstration of delete place okay so the place is successfully added and this is the place id now this is the existing address so we have moved our organization to new address so obviously i have to update it right so that is why we are using update place api now so as i said any api http method apart from get will have the payload which you need to send as part of body you cannot write that in the url okay so for that reason select the body tab and pick the json as your format right so here you have to provide the place id for which you want to update the address so right now i just added a new place right for this place i want to update with new address field okay [Music] nice next you have to give the what is the new address earlier the address was 29 side layout cohen and this time new address was 70 summer walk usa i want to update with this new address and at the same time make sure you pass the key is qa click one two three so you might be wondering why should i pass this here just follow blindly what your contract says that's it so my developer when i asked him to create i did not ask him to have this in the request body but he did it then i said okay let it be so that's the contract you should follow the rules and regulations okay so this is the constant and this is the place id for which you want to update and the new address now now let's submit this i think we have given all the details we have passed the query parameters and resource name and this is what contract says and the put http method is what we are using here great so the message what we got is address successfully updated now how to validate if we have successfully updated or not we have a get place api right we can use this place id and see what is the address it is returning back to us okay so update the place id in your get request and submit this time it should give the complete place details and there you should see 70 summer walk which you just added and the one what you added initially is now no more present okay so that's what this update place api does great so this is how add get delete update all the thread operations we have successfully discussed with different type of http methods okay now this is how you test manually through postman tool in the next lecture let's bring automation into picture and we'll see how to create end-to-end automation flow to happen all this through the rest issued java code but as per interview perspective the topics what you have learnt till now are crucial because not everyone might be expert in automating the apis but they might ask you theoretical questions to understand and check your knowledge on api right thank you
Info
Channel: Rahul Shetty Academy
Views: 47,274
Rating: 4.9570661 out of 5
Keywords: api, restapi, postman, testing, automation
Id: bdHeDZPrYec
Channel Id: undefined
Length: 75min 33sec (4533 seconds)
Published: Wed Oct 07 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.