Skip to content

Postman collection

Emi can generate a Postman v2.1 collection directly from a module. Every action becomes a Postman request, with the method, URL, and the standard Emi headers already filled in, so you can import the collection into Postman and start hitting your endpoints immediately.

The host and port are emitted as Postman environment variables ({{HOST}} and {{PORT}}), which lets you switch between local, staging and production simply by changing the active environment.

Terminal window
emi postman --path module.yaml --output ./out

Without --output, the collection JSON is printed to the terminal so you can pipe it elsewhere.

You can set the default value for the {{HOST}} and {{PORT}} variables that Postman will use:

Terminal window
emi postman --path module.yaml --host localhost --port 8080 --output ./out
FlagDescription
—pathPath of the Emi definition file (.yaml or .json) on disk.
—outputDirectory the generated collection is written to. Omit it to print to stdout.
—hostDefault value for the Postman {{HOST}} variable.
—portDefault value for the Postman {{PORT}} variable.
—tagsComma separated compile features to add or remove.

Using the postsModule from the OpenAPI page:

Terminal window
emi postman --path module.yaml --host localhost --port 8080

produces a collection whose first request looks like:

{
"info": {
"name": "postsModule",
"description": "A small module to manage posts",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "getSinglePost",
"request": {
"method": "GET",
"header": [
{ "key": "authorization", "value": "{{AUTH}}" },
{ "key": "role-id", "value": "{{RID}}" },
{ "key": "workspace-id", "value": "{{WID}}" }
],
"url": {
"raw": "http://{{HOST}}:{{PORT}}/posts/:id",
"port": "{{PORT}}",
"host": ["{{HOST}}"],
"path": ["posts", ":id"]
}
}
}
]
}

The common Emi headers (authorization, role-id, workspace-id) are wired up to Postman variables ({{AUTH}}, {{RID}}, {{WID}}), so you can fill them once in the environment and reuse them across every request.