HTTP (HyperText Transfer Protocol) is the protocol used to send and receive data over the Internet. When you make an API call, an HTTP client sends a request to an HTTP server, which then sends back a response with the requested data to the client.
An HTTP request is an action to be performed on a resource identified by a given Request-URL(baseURL). Request method names are case-sensitive, and should always be denoted in uppercase, i.e GET, POST etc.. There are various HTTP request methods with specific purposes, we use different methods for different API actions.
Let's see how we can handle HTTP methods using POSTMAN
Once you read through the Postman 101 blog, you will now have an idea on how to create Workspaces, Collections and Requests.
HTTP Requests are nothing but the action of the API.
Once you have your collection ready, you can directly go ahead and add the requests inside it.
We will now see how to add different request types under the same collection.
GET request is actually used to retrieve/read data from the server.
Create new request by selecting the three dots next to the collection name:
2. Postman generates the GET request type as default one and with default header values too. You can edit them based on your API documentation if needed
3. Add the request name and paste the URL “https://reqres.in/api/users/2” in the field next to the request type. This request doesn’t have any payload to be sent as part of “Body”
4. Click “Save” and “Send”
Tada!! We built our first request. We got the successful response back from the server.
It is the request type where need to send data to a server to create or update a resource (at times)
3. Since this is a POST request, it requires some Payload to be sent in the “Body” section
paste the below snippet under “Body“
"name": "Synapse QA",
4. Click “Save” and “Send”
We received a successful response back from the server and the user id is 261.
PUT request is used to update the existing resource/entity. Here we will try to update the same record which we created using the POST request recently.
2. Now we are filtering the user id “261” in the URL. We also need to pass the updated data as part of the “Body”
3. Click “Save” and “Send”
Now see that the entity is updated as expected.
The DELETE request method is used to delete/remove the resources mentioned in the URL.
We will delete the same user which we created using the POST request.
2. Click “Save” and “Send”
We received the response 204 error code, where server has successfully fulfilled the request and there is no additional content to send in the response payload body. Some APIs will show message like that the “User is deleted“.
We learnt how to build the different HTTP requests and received the response codes/response back from the server.
Let's see how we can handle HTTP methods using KarateDSL
Creating a Karate API Automation Framework is quite simple, you may refer to this blog, if you want to create a Karate API Automation framework from scratch.
To define the test scenario, you’ll need a feature file. We may also add multiple scenarios into single feature file.
Follow the steps below:
Step 1: Select “New” from the menu by right-clicking the package.
Step 2: Find “File” and click it.
Step 3: Add a “.feature” to the end of the filename, such as testFile.feature.
Runner file is present under the same package with “.java” extension.
Refer following code snippet to view runner class:
For running a single file, pass feature file name in Runner.path method.
If you wish to execute all the feature files in a package, use the Runner.path method to pass the package name, as illustrated below:
Following code snippet is written to handle GET method using karate.
Following code snippet is written to handle POST method using karate. In Post method, request body is passed using “request” keyword.
Like Post method, request body is also required in Put method. Hence we are using using “request” keyword.
Like Delete method, request body is also required in Put method. Hence we are using using “request” keyword.
The best thing is that we have the ability to define All of the scenarios listed above can be combined into a single feature file.
Once the execution is completed, Karate report are stored under “target” folder. (Please refresh the project if you don’t fine the report)
Copy the link generated link and paste it into any browser and hit enter.
You will get to see the latest execution report.
1. Single Feature file report.
If you want to see scenario steps in detail of feature, click on the feature file name.
2. On running multiple feature files present under a package, report look like –
Meet the brains behind this learning series!
Stay updated with all the latest contents & announcements