Using Postman Collections
Turn Postman Collections into live mock APIs instantly. Export Collection v2.1 and run with moclojer - no conversion needed. Perfect for frontend development and testing with existing Postman specs.
If you already have API specifications in Postman, you can use them directly with moclojer without any conversion. This is perfect when you have existing Postman Collections and want to quickly spin up a mock server.
What is Postman Collection Support?
moclojer can read Postman Collection v2.1 JSON files and automatically convert them into working mock endpoints. This means you can:
β Export collections from Postman
β Use them directly with moclojer
β No manual conversion or rewriting needed
β All your response examples become live endpoints
π For advanced features: See the complete Postman Collection Format Guide for variables, nested folders, multiple responses, and troubleshooting.
Quick Start
Step 1: Export from Postman
Open Postman and find your collection
Click the three dots (...) next to the collection name
Select Export
Choose Collection v2.1 format
Save the JSON file (e.g.,
my-api.json)
Step 2: Run with moclojer
That's it! Your Postman Collection is now a live mock server! π
How It Works
Moclojer reads your Postman Collection and:
Detects the format automatically - No need to specify it's a Postman Collection
Extracts all requests - Both top-level and nested in folders
Uses response examples - The first saved example becomes the mock response
Converts path variables -
:id,:username, etc. work automaticallyIncludes headers - Response headers from your examples are preserved
Respects status codes - Each example's status code is used
Example
Let's say you have this Postman Collection:
After running CONFIG=users-api.json moclojer, you can:
Response Examples in Postman
For moclojer to work properly, your Postman requests need saved response examples. Here's how to add them:
Adding a Response Example
Make a request in Postman (or use an existing one)
Click the "Save Response" button β "Save as Example"
Edit the example:
Set the status code (200, 404, etc.)
Add headers if needed
Write the response body (JSON, XML, text, etc.)
Save the example
Multiple Examples
If a request has multiple examples, moclojer uses the first one. To choose which example to use:
Reorder examples in Postman (drag and drop)
Or keep only the example you want
Nested Folders
Postman Collections can organize requests into folders. Moclojer handles this automatically:
All requests become endpoints, regardless of folder nesting. The folder structure is just for organization.
Path Variables
Postman and moclojer both use the same syntax for path variables:
http://localhost:8000/users/:id
/users/:id
β Yes
http://localhost:8000/posts/:postId/comments/:commentId
/posts/:postId/comments/:commentId
β Yes
{{baseUrl}}/users/:id
/users/:id
β Yes (variables ignored)
What's Supported
HTTP Methods
β GET, POST, PUT, DELETE, PATCH, etc.
All standard methods
Path parameters
β
:id, :name, etc.
Automatic conversion
Response status codes
β 200, 404, 500, etc.
From examples
Response headers
β All headers
From examples
Response body
β JSON, text, etc.
From examples
Nested folders
β Unlimited depth
Flattened to endpoints
Multiple requests
β Unlimited
All become endpoints
Request body
β οΈ Ignored
Only responses are mocked
Request headers
β οΈ Ignored
Only responses are mocked
Pre-request scripts
β Not supported
Postman-specific
Tests
β Not supported
Postman-specific
Variables
β Not supported
Use environment vars instead
Complete Example
Let's create a complete Postman Collection for a pet store:
1. Create in Postman
Create a collection with these requests:
GET /pets - List all pets
Response example:
200 OKBody:
[{"id": 1, "name": "Caramelo", "type": "dog"}]
GET /pets/:id - Get one pet
Response example:
200 OKBody:
{"id": 1, "name": "Caramelo", "type": "dog"}
POST /pets - Create a pet
Response example:
201 CreatedBody:
{"id": 2, "name": "New Pet", "type": "cat"}
DELETE /pets/:id - Delete a pet
Response example:
204 No ContentBody: (empty)
2. Export
Export as "Collection v2.1" β petstore.json
3. Run
4. Test
Tips and Best Practices
β
Do
Save response examples for every request you want to mock
Use realistic data in your examples
Set correct status codes (200, 201, 404, etc.)
Include headers when they matter (Content-Type, etc.)
Organize with folders for clarity
Use descriptive names for requests and examples
β Don't
Forget response examples - Without them, you get default
200 {}responseUse Postman variables in URLs - They won't be resolved (use full paths)
Rely on pre-request scripts - They won't run in moclojer
Expect request validation - moclojer doesn't validate request bodies
Comparison with Other Formats
Ease of setup
βββββ Click and export
βββ Write by hand
ββββ Generate from code
Visual editing
βββββ Postman UI
β Text editor
ββ Various tools
Dynamic responses
β Static examples
β Full templating
β οΈ Requires mocks file
Team collaboration
βββββ Built for teams
βββ Version control
ββββ Standard format
Best for
Quick mocks from existing collections
Custom logic and templates
API-first design
Next Steps
Now that you know how to use Postman Collections with moclojer:
Need dynamic responses? Continue with Dynamic Responses to learn about template variables
Want to write YAML instead? Try Your First Mock Server tutorial
Build complete APIs? See Multiple Endpoints guide
Troubleshooting
"No endpoints found"
Problem: moclojer starts but no endpoints work
Solution: Make sure your Postman requests have saved response examples
"Getting 200 with empty {}"
Problem: Endpoints return {"status": 200, "body": "{}"}
Solution: Add response examples to your Postman requests
"Path variables not working"
Problem: /users/:id always returns the same data
Solution: This is expected with Postman Collections. They use static examples. For dynamic responses based on path variables, use YAML format with templates
Ready to create your first mock? Export a Postman Collection and give it a try! π
See Also
Postman Collection Format Guide - Complete guide with advanced features
OpenAPI Format - Alternative: Use OpenAPI specifications
YAML Format Guide - Write mocks from scratch in YAML
Troubleshooting Guide - Solutions for common issues
Last updated
Was this helpful?