This project explains a better way to utilize Postman in developing and testing API Projects.
src/Emerson.Practices.Postman.PeopleDirectoryApp
- Developed using ASP.Net 8.0, the source code of the sample Rest API that the postman collection is created for.
postman\Ideal
- The ideal way of using Postman, utilizing environment, random variables, pre-request scripts, post-response scripts.postman\BadExample
- An unoptimized example of using Postman, No environment, variables, pre-scripts or post-scripts is used, all plain-old-collection of hardcoded requests.
- Clone the repo.
- Open the
src/Emerson.Practices.Postman.PeopleDirectoryApp/Emerson.Practices.Postman.PeopleDirectoryApp.sln
solution. - Run the
Emerson.Practices.Postman.PeopleDirectoryApp
project. - Wait until the swagger is loaded.
- Open your Postman and Create a new Workspace
Postman Ideal
- Load the newly created Workspace
Postman Ideal
. - Import all the collection and environments from this folder
postman\Ideal
. - Navigate to the
Collections\Main
. - Select the environment
Local
. - Run the requests 1-by-1 from
Authorization
toCleanup
folder. - You may also want to create a new Workspace and import the collections from the
postman\BadExample
folder.
- Environments, each environments contains a specific variable dedicated to the defined environment, such as:
- baseUrl
- username
- password
- Login
- The request Body contains the variable
{{username}}
and{{password}}
. - The Post-Response script contains 2 notable content.
- The test itself confirming that the response should return 200 status code.
- The setter of environment
token
based on the response of the request.
- The request Body contains the variable
- All Requests, all requests other than Login uses the
{{token}}
variable as thierAuthorization
. - Add Person
- The Pre-Request script generate new variable called
newDateOfBirth
to generate a date from 5~30 years ago. - The request Body uses the random generator variables
{{$randomFirstName}}
,{{$randomLastName}}
, and{{$randomExampleEmail}}
to generate a more realistic payload based on the needed property. - The Post-Request script stores the variable
{{personId}}
for succeeding API requests.
- The Pre-Request script generate new variable called