Authorized Post 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 lesson where we obtained an authorization token for our test application. Here, we will use this token to create a new article via a POST request. Key Steps to Create a New Article Start by defining a new constant: newArticleResponse using await request.post . Provide the URL for the POST request, which can be found in Postman. Include the body of the request under the data object. Format the document using: Option + Shift + F (Mac) Control + Shift + I (Windows) Add the authorization header : Key: authorization Value: token {token_value} (concatenated with "token space"). Validating the Response After sending the request, extract the JSON response and validate the status code: expect(newArticleResponse.status).toEqual(201); Additionally, print the response object to the console for verification. Best Practices It is recommended to follow up a POST request with a GET request to confirm the data creation. For example, after creating an article, a GET request can be made to retrieve the list of articles: Ensure to include the authorization header in the GET request as well. Validate that the first article in the response matches the article created. In summary, when making authorized requests in Playwright, always include the authorization header in both POST and GET requests to ensure proper access to private resources.