![]() In this part, we’ll look at some of Postman’s features that help us set up our testing environment. After inputting the body and clicking send, data is sent and status 201 confirms that new data has been created and the posted data shows up in the body response. It is good practice to use GET first to check the JSON format of the request. Body of a POST request should have the correct format to ensure that the data we sent will be added (request format is also something that can be tested). The way we do that is by adding the necessary body, usually in the form of raw data written in JSON. With POST requests we manipulate data, e.g. Other commonly tested request type is the POST request. In Postman an endpoint with a Path Variable is written like /cars/:id, where the ‘id’ is replaced with the value as the request is sent. Path Parameter or Path Variable is used to identify one item. cars?color=blue or /articles?sort=ASC&page=2). Query Parameters are key-value pairs used for sorting or filtering data on the server, and you can see them in a URL as what follows the question mark (e.g. This is done by submitting additional data called Parameters, such as Query and Path Parameters (Params in Postman’s main screen). When testing the response body, we usually refine our GET requests to get a specific item or we sort and filter the response. If we want to find out what exactly went wrong, we would have to debug, a step that usually follows testing. The important thing to remember about status codes is that they are just codes - they only tell us that something went wrong. Server errors or 500/5xx status codes are also ones we don’t want. The ones we definitely don’t want are the 400 or 404, or any other 4xx, which screams client error. The one we would most love to see would be the 200, 201, or any other 2xx status, because those mean success. The most important of these for testing would be the response status, or the HTTP response status code. And that’s it! We’ve manually tested our first API request in just four simple steps.Īdding and testing a GET request in 4 stepsĪfter sending our request, an answer from the server is displayed on the lower screen with information such as body (values that we’ve received), cookies, headers, response status, duration, size, and test results (if you’ve set up any tests). And then, to test the request, we click Send. In the request URL field, we input the endpoint link. Then we choose our type of request from the dropdown list. To set up a GET request in Postman, we add a new query using the New button. Endpoints are (or at least should be) listed in the API documentation, and maintaining your API documentation is just as important as maintaining your APIs. There are other methods used, but these five are the ones most commonly used.Ī request is sent to a Request URL, which is formed of a website’s base URL and the endpoint (the point where your request will end up and from which we get a response). These requests are based on HTTP methods that the API uses for CRUD (create/read/update/delete) operations: GET for reading or getting data from API, POST for creating new data PUT which sends data but also edits data that have changed, PATCH for editing individual resource data, and DELETE for deleting data. The main part of any API testing is setting up requests (or calls) and testing them either manually or by adding test scripts (and eventually automating those tests). ![]() and the lower screen, which shows response properties like status code, response body, test results, or Postman console. The application interface shows your workspace and consists of: side menu with collections the main view where you configure requests, with tabs for specifying headers and parameter settings, the body of a request, test scripts, etc. After installing it, you can then create an account and log in. Postman can be freely run in a browser or used as a standalone desktop application. What we test is the connection and the responses we get. In Postman we send requests to connect to an API and we communicate with its servers in order to receive responses. ![]() The reason why it’s so popular is the advantages it has over other tools: it is easily accessible and open source, with a lot of existing support, it features collections, environments, and collaboration, test creation, automation, support for continuous integration, etc.Īs testers, we use Postman to interact with web-based APIs. Postman is the leading platform for API development and one of the most popular low-code API testing tools. This blog will describe basic API testing using our preferred tool - Postman. In the first blog on API testing, we introduced API testing in general.
0 Comments
Leave a Reply. |