hi everyone welcome you all so earlier I have done series on web automation testing using Cypress so basically Cyprus will also support API testing so we can test rest apis uh using Cyprus now from today let us start a new series on Cyprus API testing so for that we need to set up an environment so which is exactly the same so which I already discussed in the previous sessions so if I just look at my Series so the part 2 Cyprus Android web automation environment setup on Windows or Mac OS so this is exactly the same for API testing also so to set up the environment you can just watch this video and you will understand how we can set up the environment for testing apis using Cypress so first thing we need to have is we need to install node.js npm package and then we need to also download install and visual studio code editor and after that we have to install Cyprus package so these are the three important things which we need to have before starting testing on AP it can be baby testing or repair testing the environment setup is exactly the same so please watch this video so before setting up the environment and now I am directly jumping into the API testing using Cypress so here I have Visual Studio coordinator which is already installed and now I have created a new project called Cypress automation and this is a default folder structure you can see as soon as you create a new project in Cyprus so under e2e folder you can see all the specification files we can create answer inside the e2a folder all right so now these are all web test cases I have already done earlier now I'm going to create APA test cases so for that I'm going to create a new folder inside the end-to-end folder so let me take the new folder and I will name it as API testing so whatever API test cases I will write everything should be part of this API testing okay so as part of today's video first let us see the the basic HTTP request then how we can send get call or post request or get request and put request and then daily take question and very basic uh we'll see first and then I'll show you some more options in those requests so first let us start creating a new test in which we will try to send different type of HTTP request so first thing let me create under API testing I am going to create a new file so in Cyprus whenever you create a spec file so the extension should be the file name.cy.js so here I'm writing my file name is http request Dot Cy dot Js so this is my file which is created under API testing now we'll see how we can send different type of request in Cyprus so before that we need to First write a describe block so which contains a it blocks so whenever you write a test cases in Cyprus we need to First write a describe block so this is uh similar to the test suit and which contains eight block which contains a test so now I'm writing the describe right so inside this we need to specify the some description let's say http request I'm writing some description and along with this Arrow function we have to implement like this so inside this describe block we need to write multiple tests using it block so first eight block I'm writing here I say it and again which will take two paraben two parameters so first parameter I'm just giving some description let's say get call and the second parameter should be Arrow function and this add a function I'm going to implement here all right so first before getting the call before sending the get request we need to know the URL right so I'm going to use Postman tool now let's go and see the postman tool first and then I'll use the same kind of request in the Cypress and if I go back to my collection testing there is a get call here now this is a URL I'm going to send as part of get request and uh which when I send this you will get the response like this user id id and the title and then some body you got it so this is a response you got when you send this get request now same request I'm going to send in Cypress so to send any request any type of request we need to do something called c y dot request module okay Cy dot request model so inside this we need to pass two parameters the first parameter should be what type of call you are going to send get you can put in the double quotations or single quotation no problem so get call I want to send and what is the URL you want to send so that URL you can keep inside the quotations like this so get is a type of request and what URL you want to send as part of get request so that we need to specify so once you send this URL we need to verify something right so we need to just say I want to verify my simple status quo so how we can verify dot it's here we can specify what you want to verify so I want to verify the status of the request I can simply say status and what the status should be that you can put one assertion should equal to so I can use equal so equal to the value is 200. so this is how we need to send the get request so other than the status code we can also verify the body and response content on all those things so that we will discuss later so as part of this video let me show you the basic stuff how we can simply send different type of requests in Cyprus so now I'm sending the get request get code so let us try to execute this and see how it is going to work so once you've created just save the file and now to run this first of all let's try to open the terminal so we can run this big file in multiple ways we can run through Cypress application or we can directly run through command prompt so if you want to run through this command prompt simply you can run one command in the terminal npx Cypress iPhone iPhone so NPS I plus run so if I leave this command like this which will run all the specifications which are there under e to a folder but I want to execute a specific specification file which is part of API testing folder so to run the specific specifically what you can do is npx Cypress Run space iPhone iPhone spec this is a one keyword we have to use iPhone iPhone spec space now we can provide the exactly the location of the file which you want to execute so I'm just copying the relative path and then paste it over here like this okay so now this particular command NPS Cypress Run iPhone spare space that location of the file so this file is going to be executed now let me just execute this so now it is started executing my get request and now it is successfully got executed so everything is got passed so you can just see the result test has got passed so this is the one way we can execute the request there is another way also there through Cyprus application we can execute so for that we need to run one more command uh Cyprus NPS npx Cyprus okay so this command will open Cyprus application window and through that window also we can run the test so NPS Cyprus open so once executed this command which will open Cyprus window like this and select end-to-end testing and start e2e testing in electron by default and here you can choose whichever spec file you want to execute so I want to execute this HTTP request which was there under API testing now I click on this now it is started executing the get called and now my assertion has got passed so this is another way we can execute the file in your Cypress okay so now let me show you how we can do the uh put call and the post call and then delete call so what I'll do is let me close my terminal so let me write another 8 block to perform the post request so before that let me show you in the postman tool let's go to postman now if I go back to the post call so this is my post request and this is the URL I'm using so whenever you are trying to post you have to send a some content so we need to send a request body along with the URL so this is the request what I want to send title and body and some user ID so once you this sent through post URL and as part of the response you will get some ID will be generated so not this user ID some other ID will be generated so let me try to execute this post request in the postman so once I executed so you will get some response here so title body user ID we have provided but IDs got generated newly here id101 has got generated so this is the response we will get and this is a request we have to do so now we'll see how we can send this post request in Cypress to get the response so for that we let's create one more it block right so it and again two parameters so I name it as post call and the second parameter should be Arrow function and this function we need to implement so this is another test for postcard so it can be any type of call so we have to use Cy dot request so I can say Cy dot request and inside this what uh what type of method you are going to send post request we understand so because we are doing the post request here we want to pass multiple parameters three parameters we have to pass so first one is request type second parameter is URL third parameter is a body for a get request the body is not there so we pass only two parameters but in case of post request we need to pass three parameters okay so the first parameter all three parameters should be part of curly braces so we need to keep one curly braces insert the request like this or you can put in multiple lines also so this is a only request part this is only request part okay so inside this so inside this we need to specify three things one is type of method you are sending so how we can specify that we can specify method method is a parameter so method colon what method you want to send post so I say post comma so what type of URL you want to send so that also we need to specify URL in the quotations we need to spend we need to specify the post URL so let me copy my post URL here so this is my post URL comma so after that you want to specify the body also right because it is a post request we need to send a body also so the next parameter should be body and how we can specify the body is again in one more curly braces because the body in the Json format so we need to specify the body inside another curly braces so here we need to specify so if I go back to the postman so this is the body which I have sent through request so now I'm copying the same body and then paste it over here but we need to follow proper syntax here when you send the body curly brace you already keep it here and and here just remove this so we should not put the double quotation for the fields especially in Cyprus so we can just remove them so we have to remove them so values are fine values you can keep in the double quotations or single quotation no problem so this is our entire body section so three things we have passed inside the requester so you can put everything in one single line or we can put in multiple Lines no problem so basically this is a whole request so in the request we pass method URL and then body so this curly braces got closed here the request bracket is got closed here so overall the request is got sent post request so once you send a post request we want to verify the status again after that again same process I can say dot it's so inside this what we want to verify I want to verify the status quo I can say status and dark should again equal to what 201 because there's a post request will be generated two zero one is so now I'm just closing this so this is how we can simply send post request inside press and we can verify the status code so once you send a post request we can also verify the body okay so that we will discuss later so first of all let us focus on how we can send different type of requests so get request we have successfully send and verify the status code now we are sending the post request and now again verifying the status quo so this is how we can send the post call all right now let us uh test this and execute now I'm saving the file again so when I run this by default both the requests will be executed so let me go back and open the terminal so in the terminal again I'm writing I am executing the code in the command prompt itself so npx Cypress Run in BX Cypress Run iPhone spec and then we need to specify the specification file and here we need to specify the location of the specification file just copy the relative bar and then specify here that's it so let's execute this so now we have executed two types of requests post request first get request and post request so both are successfully got passed okay so two types of requests we have sent both have been successfully passed so this is how we can simply send post request in Cyprus so now let me show you how we can send put request which is basically used for updating the existing record so now we need to write another eight block so before that let me go to post main tool now let me show you how we can do the put call now I have created another call called put call and this is a URL and this is a body which we need to send along with this URL and uh these three details we need to already there in the database now this additionally which user or which record we want to update so that ID also we need to pass here so this particular body we have to send along with this put request so when you send this it will go and update like this okay this is got updated so now let us send the same request in Cyprus so for that again I'll write one more it block two parameters the first parameter is this is put call and uh the second parameter should be Arrow function so inside this we need to send it sorry so now this time again we use the same kind of request C by dot request and this time what is the method we have to use again three parameters one first parameter is a type of a method which is put second parameter is a URL third parameter is a body exactly the same whatever you have sent here the same thing we have to pass again so c y dot request and here you need to take a curly brace right so inside this we need to specify the request body so to specify the request body the first thing is what method what method you want to send so method is water put call I say method is voltage so that we can keep it in the singular double quotations fine and next parameter is what we need to pass URL so URL we need to mask single quotation or double quotation anything is fine so I am taking this URL and then I'm sending it into as part of URL so this is a URL okay fine so we have sent method and URL so what else we need to pass we need to pass body so what do we need to update that also we need to pass so that we need to keep inside the body body and that we can include inside the curly braces again because this is a Json format so now whatever body we are sending here the same thing should be part of this body here okay but make sure as per the Cyprus syntax we should not use double quotations for the particular fields so singular double quotations we should not only the data should be included in the singular double quotations but this field should not be added so this is the body which we are going to send idle body user ID and ID so this is the body so once this body parameter is also done so now the request is got completed so from here the request is got started Cy dot request this is the whole thing we have to pass right so this bracket is got closed and this bracket we should close still it is not got closed so this is the bracket clause I think this is extra one let me keep it here okay so if I look at this request Cy dot request in the curly brace we specified a method URL body so this body curly braces end here and this request curly brace should be end here and then the request open bracket is already ended here so with this request is successfully completed fine so after that continuation so what we need to verify so let's verify the status quo Dot it's what you need to verify we need to verify the status and again should be should equal to right so equal to I can say 200. right so then close this so this is how we can put the validation for put call okay now let us execute a test now this time I'm executing all the three requests get request post request and then put request let me save the file and go to the terminal and run the command one more time so here NPI Cypress Run iPhone spec and then we need to specify the location or path of this particular file so that we can exude only that particular specific specific specification file so nowadays I got executed so three different type of request we have sent and one is get call Post call and then put call all three got successfully executed so let us run them through uh Cypress application so for that what you can do is we can simply execute npx Cyprus open so this command will open Cyprus application so once it is got open so you can select this end-to-end testing then click on the button now you can see this is HTTP request now I'm clicking on this now it is started executing all three types of request so this is how we can simply execute apis in the Cyprus now let me show you one more type of request which is delete all so same thing again so we need to write one more hit block so I'm just writing one more in block it and two parameters the first parameter should be description this is my delete call and arrow function and this function we need to implement here so what is the first thing we need to do we need to First specify the type of request so what type of request we are going to send Cy Dot request cv.request and in the bracket so how many types of requests only two type of request right so you can simply say the first paragraph in the curly braces we need to specify in the curly braces so what is the type of method we want to send now this method is what deleted so in the single quotations you can specify the delete this is the delete call we want to send what is the URL you want to send you can say simply URL the double quotation whatever URL you are going to use for deletion you can use it so currently I am using this delete call for this URL copy this and then specify this so this particular request will go and delete the first record so this is how we can simply send this curly brace is closed here the request is got closed here so then we can start validating so here you can simply say dot it's status okay and that should be equal to assertion should equals and obviously it will be 200 and then close it so this is how we can simply write a request so if I look at this request different type of request in our get call I have used this syntax right the first parameter I directly specify the method name and then I directly specify the URL and if you look at this rest of the things I I specify them all parameters in the curly braces and here I have not used a method parameter method keyword I directly specify the type of method and URL also a keyword I have not used right so directly specified this and both the syntaxes will correct so if you want to specifically say method is get and URL is this one just like delete request you can specify so in the delete request even though we have a two parameters method and URL you can put them directly in the curly place but if you don't want to use curly braces then this keyword also not required so directly you can specify the method name comma the URL whatever you want okay but in the post post call and put call we have another parameters called body so that we can specify in the curly braces so this is a syntax which we need to follow in Cyprus now this is a another block for delete code so let us try to execute all the spec and see one by one so let me save it and again open the new terminal and now let me try to execute so npx Cyprus run iPhone spec and then we need to copy the file location copy relative path and then specify here okay and then execute so four type of requests we are sending first get then post put and then delete so all four type of requests successfully executed now again if you want to run them in Cyprus application you can simply run this command npx Cypress open so open this command spelling mistake npx Cyprus open so this command will open Cyprus window and here we can execute this command so here hdb request totally four requests we have sent and all four requests have successfully executed and my assertion is also got passed so this is a simple way we can simply uh send different type of HTTP calls through Cypress and we don't need any additional libraries required so whatever Cyprus you have successfully installed by default whatever packages you will get along with the Cyprus with those packages we can still do it API testing okay so in the next videos we will detail and discuss about how many ways we can verify the response okay and what are all other things we can validate other things other than this status code what are other things we can validate so these things we will see in the next video all right so that's all for this video thanks for watching we'll see in the next video