A key feature of using REST services is the easy nature of doing testing through the browser. One thing that is more difficult to test via the browser are POST api methods which require you to send data through the request body. In this post we will discuss an easy method of testing POST api methods via a chrome plugin called Postman.
Step 1: Download the Chrome Web Store App
Go to the chrome web store and download “Postman – REST Client”.
Step 2: Use Postman to get data via a GET
- For quickly testing POST methods we will first get some JSON data by first doing a GET. The easiest way to get to testing a POST method is to retrieve a record from the database that already exists, then using the structure of the JSON string returned and just changing the values and resending as a POST request.
- Enter the url into the line that says “Enter request URL here”, leave GET in the dropdown, and hit the Send button
Step 3: Use the JSON string to test a POST method
- Now that you have the JSON string with the correct structure of the object you want to POST to the server you can now send a POST
- Start by clicking on the drop down list with the all the Http methods and select POST
- Select the “raw” button and then click on the drop down directly next to the raw button and select JSON
- Copy the Json string that was returned from the GET and paste it into the text area
- Click on the Headers button. Add a new header for content type by entering Content-Type where it says Header and then enter application/json;charset=UTF-8 for the Value.
- Change the Url to point at the POST method.
- Change the values of the JSON data you want to send and click the Send button
A nice feature of the Postman chrome app is that your state is remembered and all data for both requests and headers are there when you re-open it. So once you add the new Json content type to the header it will be remembered every time you open the Postman app. This is a nice tool that we will be able to utilize for quickly testing our REST services going forward.