Skip to content

Interface with a Postman collection, and get request data from nested structure - mostly to be used as mock data in mocha+chai tests.

License

Notifications You must be signed in to change notification settings

muhammad-bin-zafar/postman-collection-interface-library

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pcolib-logo

API

Run a request

The argument example of method Pcolib.prototype.run() is optional. If omitted, the data present in original request is used.

import collection from './postman.json' assert {type: 'json'}
import Pcolib from 'postman-collection-interface'

const pcolib = new Pcolib({ collection })
pcolib.run('folder-name', 'request-name', 'example-name')

Specify by method-chaining

pcolib.get('folder', 'req').example('ex').run()

pcolib.get('folder').request('req').example('ex').run()

Specify request data

pcolib.get('public-api', 'user login').body({ name: 'muhammad' }).run()

pcolib.get('public-api')
	.request('user login')
	.body({ name: 'muhammad' })
	.headers({ etag: 'etag-token' })
	.run()

Get request data

const {body, query, headers, params} = pcolib.get('public-api', 'user login', 'dev: ok')

URL

Pcolib parses and looks out for query parameters and path variables. If these data are specified by user, then they're used to make the request. If a URL in postman is as: /user/{{user_id}}/repositories/{{repo_id}}, then:

pcolib.get('user code repo')
	.request('get single repo')
	.headers({ authorization: 'Bearer xyz' })
	.params({ user_id: 'f7kla9-09kda', repo_id: '345678' })

Stateful requests

Pcolib instances can be a mock for a user. Often useful in end-to-end testing. If global payload is specified, all requests from the instance will contain the payload.

const admin = new Pcolib({
	collection,
	global: { headers: { authorization: 'Bearer admin' } }
})
const shop = new Pcolib({
	collection,
	global: { headers: { authorization: 'Bearer shop' } }
})
const user = new Pcolib({
	collection,
	global: { headers: { authorization: 'Bearer user' } }
})

user.get('cart', 'checkout').run()
shop.get('order', 'list').run()
admin.get('analytics', 'past orders').query({ pastDays: 30 }).run()

About

Interface with a Postman collection, and get request data from nested structure - mostly to be used as mock data in mocha+chai tests.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 92.5%
  • JavaScript 6.9%
  • Shell 0.6%