Get Request in Karate DSL with Example

This entry is part 1 of 4 in the series Karate Dsl Tutorial

In this example, we will see “How to send a GET request to a Rest API endpoint using Karate DSL library?”. If you are starting from scratch, then first go see this article as it will teach you how to set up Karate project in you IDE and configure required dependencies. 

Get_Request_Karate_Dsl_Featured_Image_Techndeck

Simple example of GET Request using Karate DSL...!!! Click To Tweet

In this tutorial, we are going to cover below topics:

  1. What is Get Request?
  2. How to send GET request using Karate?
  3. Response Validation

 

Check out: GET REQUEST using Apache HttpClient in JAVA

Let’s begin:

1. What is GET Request?

GET method is one of the most common method of HTTP Protocol which is used to request data from a specific resource.

Some key points of GET requests:

  • GET requests parameters remain in the browser history because they have been sent as part of the URL
  • GET requests can only be used to retrieve data not to modify
  • GET requests can be cached
  • GET requests are less secure and should be avoided when trying to retrieve data from a sensitive resource
  • GET requests parameter data is limited as there are lengh restrictions
  • GET requests can be bookmarked
  • GET requests only allow ASCII characters
  • GET requests are prone to get hacked easily

 

2. How to send GET request using Karate?

Before proceeding, lets set up your project by following this article. 

Let’s take an example of one of the API GET endpoint available at the above-mentioned website which is ‘/employees’. The full-service URL with endpoint is ‘http://dummy.restapiexample.com/api/v1/employees‘.

At the above resource URL, information about all the employees is present and now we are trying to access those employees details in this below example like id, employee_name, employee_age, employee_salary and profile_image.

Code to send the GET request to the above mentioned Service Endpoint (getRequestTest.feature):

Let’s try to understand the code:

1. Specifying the Feature & Scenario (typical cucumber format)

2. Setting up Endpoint URI in ‘Given’ 

Endpoint URI is the address to the Resource. And, by this particular line of code, we are specifying to Karate to use “dummy.restapiexample.com/api/v1” as the root URL of the service.

3. Specifying the type of request (GET) in ‘When’ condition

4. Checking up Status Code & other Response validations in ‘Then’

 

3. Response Validation

a. status 200 : It will check the status code coming back from the service is 200

b. print ‘Response is: ‘, response : This line of code will print the response from the service in the console.

c. match response contains {“id”:”6411″,”employee_name”:”dts44″,”employee_salary”:”3″,”employee_age”:”3″,”profile_image”:””} : This line of code helps to check if the specified content is present in the response or not.

Testng Report:

Get_Request_Junit_Report_Karate_Techndeck

Eclipse Console Output:

That’s it, it’s that simple to make a GET method Request using Karate DSL API: ?

 

Simple example of GET Request using Karate...!!! Click To Tweet

If you like this post , please check out my other useful blog posts:

Other Useful References:

Related Posts:

[wcp-carousel id=”5342″]
Series NavigationPost Request in Karate DSL with Example >>

Leave a Reply

Your email address will not be published.Required fields are marked *

Facebook Twitter Instagram YouTube