Delete API Request using Playwright

Profile picture for user arilio666

This article will show how we can DELETE requests using a playwright.

  • An API DELETE request is an HTTP request method to delete a resource identified by a specific URL. 
  • The DELETE method removes or deletes the specified resource from the server.

Demo API

Let's use the DELETE API of the reqres website for the demo.

Here, we should get status code 204 when the DELETE request is done.

Step 1: Use the request instance as a parameter.

test.only('two', async ({request}) => { }
    

Step 2: Send HTTP DELETE Request.

const response = await request.delete('https://reqres.in/api/users/2');

Step 3: Verify the status code of the response is 204.

expect(response.status()).toBe(204)

Code:

 test.only('two', async ({request}) => {

       
       const response = await request.delete('https://reqres.in/api/users/2');
       
     expect(response.status()).toBe(204)

           });
   });