Testing is an integral part of your application delivery. I have covered a full details on testing here:
Before diving deep, let's understand a bit about Postman.
Postman is an API client that makes it simple to create, share, test, and document APIs. Users can construct and save simple and sophisticated HTTP/s queries, as well as view their responses. It was created as a part of a side hustle and eventually turned to a fully functional product.
In this tutorial we will see how we can effectively use Postman to test our MuleSoft API.
Every MuleSoft API starts with a good RAML(or OAS) Design. We design a good RAML(or OAS) based specification and then implement it to connect to end systems.
Postman allows us to import this RAML directly and it creates the API stubs.
- Let's create a simple RAML based spec
- We will then open postman and click on Import
- Import opens multiple options like File, Folder, Link etc.
- We will download the previously created RAML and upload as a file
- Import as Documentation
- APIs will appear in Collection with proper structure
- Base URL variable
On clicking (1) we can see a variable called baseUrl(2) is created automatically. Here we can add the basepath of the api like "https://<domain>/api"
- Base URL variable injected to each API call
The value of the baseUrl will then be injected and you can call your APIs. Also note the path param(:id) is also created out of the box.
- Adding Tests
We can add tests in postman to validate our responses.
Example, we can validate the API returns 200 as below:
I covered a simple test here to show the power of postman. We can add various tests and evaluate our API against it.
There's so much to postman and one article can hardly cover it all. Hope you liked this one. I will post more tips and tricks of postman in future. Cheers 🍻