API testing & How to perform API testing for POST and GET methods in Cypress

Reading Time: 2 minutes

In this blog, you will learn to understand how to perform API testing for GET and POST in cypress with code and output.

What is an API?

API(Application Programming Interface) In software application (app) development, Although API is the middle layer between the presentation (UI) and the database layer. Above all APIs enable communication and data exchange from one software system to another.

What is Cypress?

Cypress framework is a JavaScript-based end-to-end testing framework built on top of Mocha – a feature-rich JavaScript test framework running on and in the browser, making asynchronous testing simple and convenient.

Therefore, it also uses a BDD/TDD assertion library and a browser to pair with any JavaScript testing framework.

What is an API Testing?

It is a software testing practice that tests the APIs directly from their functionality, reliability, and performance, to security.In addition it effectively validates the logic of the build architecture within a short amount of time known as API testing.

Get Method in Cypress:

To perform a Get operation, we shall make an HTTP request with the cy.request() whereas pass the method GET and URL as parameters to that method.

The status code reflects although the request has been accepted and handled correctly. However the code 200(means ok) and 201(means created).

Implementation of GET Method in API testing:

The implementation of GET method in Cypress is explained below −

describe('API testing for GET and POST in cypress',function(){
    it('GET Method',function(){
   cy.request("GET", "https://reqres.in/api/users/2", {
      }).then((r) => {


Post Method:

While using the POST method, Whenever we actually sending information.

If we have a group of entities , we can append new ones at the end, with the help of Post.

To perform a POST operation, we shall make an HTTP request with the cy.request() and pass the method Post and URL as parameters to that method.

Implementation of POST Method in API testing:

Given below is an implementation of POST method in Cypress −

describe('API testing for GET and POST in cypress',function(){
    it('Post Method',function(){
        method: 'POST',
        body: {
          "name": "morpheus",
          "job": "leader"




Written by 

I am a software Consultant-QA at knoldus Inc in test automation studio. She is familiar with the core concepts of manual testing and automated testing using Selenium and cypress. She is always eager to acquire new tech skills and learn new & advanced concepts to advance herself. She likes to watch web series and listening music.