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.
Generating the collection
Section titled “Generating the collection”emi postman --path module.yaml --output ./outWithout --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:
emi postman --path module.yaml --host localhost --port 8080 --output ./outOptions
Section titled “Options”| Flag | Description |
|---|---|
—path | Path of the Emi definition file (.yaml or .json) on disk. |
—output | Directory the generated collection is written to. Omit it to print to stdout. |
—host | Default value for the Postman {{HOST}} variable. |
—port | Default value for the Postman {{PORT}} variable. |
—tags | Comma separated compile features to add or remove. |
Example
Section titled “Example”Using the postsModule from the OpenAPI page:
emi postman --path module.yaml --host localhost --port 8080produces 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.