Delete Request | Bondar Academy
Course: Playwright API Testing with TypeScript
Module: API Testing Basics
Instructor: Artem Bondar
Lesson Summary
In this lesson, we build upon the previous one where we created an authorized post request to create a new article. The focus now is on adding a final step to delete the article , allowing us to rerun the test without encountering issues related to duplicate articles. Key Concepts The delete request does not require a request body; it only needs the URL, which includes a unique identifier for the article. Authorization token must be provided to perform the delete request. The response from the post request contains a slug , which serves as the unique ID for the article. Steps to Implement the Delete Request After making the post request, save the slug into a constant: const slugID = newArticleResponse.json().article.slug; Create the delete request using the saved slug ID: const deleteArticleResponse = await request.delete(`url/${slugID}`, { headers: { Authorization: 'Bearer token' } }); Validate the response status code: expect(deleteArticleResponse.status()).toBe(204); Summary of the Lesson To make a delete request in Playwright , use the delete method within the request fixture. Utilize interpolation for dynamic URL values by using backticks and the syntax ${variable} . Always provide headers for secure APIs and validate the status code to ensure the request was successful. By implementing these steps, we ensure that our tests can be run repeatedly without issues, maintaining a clean testing environment.