Postman and Faker

I am a huge fan of Postman when developing API’s. I dont think i use even 20% of its abilities.

Today I found out that the Postman Pre-request scripts also have access to Faker.

Here is an example dynamic request body for creating a user.

const randomInt = Math.floor((Math.random()*100 +1));

const firstName = pm.variables.replaceIn("{{$randomFirstName}}");
const lastName = pm.variables.replaceIn("{{$randomLastName}}");
const domain = pm.variables.replaceIn("{{$randomCompanyName}}").replace(/[, ]+/g, ".").trim();


const body = {
firstName,
lastName,
email: ${firstName}.${lastName}@${domain}.c
om

}

pm.environment.set('body', JSON.stringify(body))

Here is Postman’s list of Faker options

https://learning.postman.com/docs/writing-scripts/script-references/variables-list/