Skip to content

Commit 8ea9857

Browse files
committed
Merge remote-tracking branch 'origin/develop' into develop
2 parents 5c48399 + 670575d commit 8ea9857

5 files changed

Lines changed: 288 additions & 141 deletions

File tree

docs/get-started/installation.md

Lines changed: 86 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,41 @@
11
---
22
title: "Install Mokapi: Quick & Easy Setup Guide"
3-
description: Learn how to install Mokapi effortlessly across Windows, macOS, and Linux. Follow the step-by-step guide for a smooth setup experience.
3+
description: Install Mokapi on Windows, macOS, Linux, Docker, or Node.js. Follow a simple step-by-step guide to get started quickly.
4+
subtitle: Get Mokapi running in seconds on Windows, macOS, Linux, Docker, or Node.js.
5+
cards:
6+
items:
7+
- title: Run Your First Mock
8+
href: /docs/get-started/running
9+
description: Learn how to start Mokapi and mock your first API
10+
- title: Explore Tutorials
11+
href: /resources
12+
description: Follow step-by-step guides for REST, Kafka, LDAP, and SMTP
13+
- title: Write Scripts
14+
href: /docs/javascript-api/overview
15+
description: Add dynamic behavior to your mocks with JavaScript
16+
- title: Configure Mokapi
17+
href: /docs/configuration/overview
18+
description: Customize ports, providers, and other settings
419
---
520
# Install Mokapi
621

7-
Mokapi is an open-source tool designed to simplify API mocking and schema validation.
8-
It enables developers to prototype, test, and demonstrate APIs with realistic data and
9-
scenarios. This guide provides straightforward instructions to install Mokapi on various
10-
platforms.
22+
## Overview
23+
24+
Mokapi is an open-source API mocking tool that helps you develop and test faster by simulating REST APIs, Kafka topics,
25+
LDAP directories, and SMTP servers. This guide shows you how to install Mokapi on your platform.
26+
27+
Choose your preferred installation method based on your platform and workflow.
28+
29+
```` box=benefits title="Try Without Installing"
30+
Test Mokapi instantly with npx (requires Node.js):
31+
32+
```bash style=simple
33+
npx go-mokapi serve https://petstore3.swagger.io/api/v3/openapi.json
34+
```
35+
36+
37+
This starts a mock server immediately without permanent installation. Perfect for quick tests and demos.
38+
````
1139

1240
## Installation Options
1341

@@ -16,23 +44,39 @@ Choose your preferred method below:
1644

1745
::: tabs
1846

47+
@tab "NPM"
48+
49+
If you prefer to install Mokapi globally as a Node.js package, install [go-mokapi](https://www.npmjs.com/package/go-mokapi)
50+
using:
51+
52+
```bash
53+
npm install -g go-mokapi
54+
```
55+
56+
After installation, the mokapi command is available globally.
57+
1958
@tab "macOS"
2059

2160
### Homebrew
2261

62+
Install via Homebrew for easy updates and management:
63+
2364
```bash
2465
brew tap marle3003/tap
2566
brew install mokapi
2667
```
2768

2869
### Direct Download
2970

30-
Download the latest macOS version from [GitHub](https://github.com/marle3003/mokapi/releases)
71+
Download the latest macOS binary from [GitHub](https://github.com/marle3003/mokapi/releases). Extract
72+
archive and move the binary to your PATH.
3173

3274
@tab "Windows"
3375

3476
### Chocolatey
3577

78+
Install via Chocolatey for easy updates:
79+
3680
```Powershell
3781
choco install mokapi
3882
```
@@ -43,6 +87,8 @@ Download the latest Windows version from [GitHub](https://github.com/marle3003/m
4387

4488
@tab "Linux"
4589

90+
Download the .deb package from the releases page and install:
91+
4692
### Direct Download
4793

4894
Download file appropriate for your Linux distribution and ARCH from the [release page](https://github.com/marle3003/mokapi/releases), then install with
@@ -57,34 +103,54 @@ rpm -i mokapi_{version}_linux_{arch}.rpm
57103

58104
@tab "Docker"
59105

60-
To get started with Mokapi using Docker, visit [DockerHub](https://hub.docker.com/r/mokapi/mokapi/tags) for a list of available images.
61-
You can also use a custom base Docker image as demonstrated in [these examples](/resources/examples/mokapi-with-custom-base-image.md).
106+
Mokapi provides official Docker images on [Docker Hub](https://hub.docker.com/r/mokapi/mokapi):
62107

63108
```
64109
docker pull mokapi/mokapi
65110
```
66111

67-
@tab "NPM"
112+
:::
68113

69-
If you prefer to install Mokapi as a Node.js package, install [go-mokapi](https://www.npmjs.com/package/go-mokapi)
70-
using:
114+
```` box=info title="Verify Installation"
115+
After installation, verify Mokapi is working:
71116
72-
```bash
73-
npm install -g go-mokapi
117+
```bash style=simple
118+
mokapi --version
74119
```
75120
76-
:::
121+
````
77122

78-
### Mokapi Scripts Type Definitions
123+
## TypeScript Support
79124

80-
Mokapi allows you to write **custom scripts** to handle API events or modify responses.
81-
For full type safety and autocompletion in TypeScript, you can install the [`@types/mokapi`](https://www.npmjs.com/package/@types/mokapi`) package:
125+
For full type safety and autocompletion when writing Mokapi scripts in TypeScript, install the type definitions:
82126

83127
```bash
84128
npm install --save-dev @types/mokapi
85129
```
86130

87-
## Next steps
131+
This enables IntelliSense and type checking in your IDE when writing custom event handlers and scripts.
132+
133+
### Example TypeScript Script
134+
135+
```typescript title=petstore.ts
136+
import { on } from 'mokapi'
137+
138+
export default function() {
139+
on('http', (request, response) => {
140+
// TypeScript provides full autocompletion here
141+
if (request.path.petId === '999') {
142+
response.statusCode = 404
143+
response.data = { message: 'Pet not found' }
144+
}
145+
})
146+
}
147+
```
148+
``` box=tip title="IDE Integration"
149+
With @types/mokapi installed, editors like VS Code will provide autocompletion for Mokapi's API, making script development faster and less error-prone.
150+
```
151+
152+
## What's Next?
153+
154+
Now that Mokapi is installed, here's what you can do:
88155

89-
- [Create your first Mock](/docs/get-started/running.md)
90-
- [Install @types/mokapi](https://www.npmjs.com/package/@types/mokapi)
156+
{{ card-grid key="cards" }}

docs/get-started/test-data.md

Lines changed: 117 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,52 @@
11
---
2-
title: Mocking APIs with Realistic Test Data
2+
title: Generate Realistic Test Data
33
description: Mokapi generates random realistic test data or lets you customize responses with JavaScript to match your specific use case and scenarios.
4+
subtitle: Mokapi automatically generates realistic test data from your API specifications. Customize responses with JavaScript or use declarative formats to match your exact testing needs.
5+
cards:
6+
items:
7+
- title: Dashboard Guide
8+
href: docs/get-started/dashboard
9+
description: Learn how to validate and visualize your mock data
10+
- title: Write Scripts
11+
href: /docs/javascript-api/overview
12+
description: Add dynamic behavior to your mocks with JavaScript
13+
- title: Configure Mokapi
14+
href: /docs/configuration/overview
15+
description: Customize ports, providers, and other settings
16+
- title: Explore Tutorials
17+
href: /resources
18+
description: Follow step-by-step guides for REST, Kafka, LDAP, and SMTP
419
---
520

6-
# Mocking APIs with Realistic Test Data
21+
# Generate Realistic Test Data
722

823
Creating reliable test data is essential for accurate API testing and development.
924
Mokapi provides a powerful data generation engine that creates realistic test data
10-
based on API specifications. You can customize and control the generated data using
11-
JavaScript scripts or declarative configurations to adapt it to real-world scenarios.
25+
based on your API specifications.
26+
27+
You have multiple options for controlling generated data:
28+
29+
- **Automatic Generation**
30+
Mokapi analyzes your schema and generates context-aware, realistic data automatically
31+
- **Declarative Formats**
32+
Use standard formats like `date`, `email`, `uuid` in your schema
33+
- **JavaScript Customization**
34+
Extend the generator with custom logic for specific fields or patterns
35+
- **Full Response Control**
36+
Write complete response handlers with conditional logic and dynamic behavior
1237

1338
## Automatic Test Data Generation
1439

15-
By default, Mokapi analyzes your API’s data structure and types to generate meaningful responses.
16-
Additionally, Mokapi tailors responses based on request parameters, ensuring relevant data is returned.
17-
For example, if a request filters for available pets, the response will include only pets with the status *available*.
40+
By default, Mokapi analyzes your API's data structure and types to generate
41+
meaningful responses. It also tailors responses based on request parameters,
42+
ensuring relevant data is returned.
43+
44+
### Context-Aware Generation
45+
46+
For example, if a request filters for available pets, the response includes
47+
only pets with `status: "available":
1848

19-
```bash tab=/pet/4
49+
```bash tab=Single Pet
2050
GET http://localhost/api/v3/pet/4
2151
HTTP/1.1 200 OK
2252
Content-Type: application/json
@@ -39,7 +69,7 @@ Content-Type: application/json
3969
"status": "pending"
4070
}
4171
```
42-
```bash tab=/pet/findByStatus
72+
```bash tab=Filtered List
4373
GET http://localhost/api/v3/pet/findByStatus?status=available
4474
HTTP/1.1 200 OK
4575
Content-Type: application/json
@@ -54,17 +84,57 @@ Content-Type: application/json
5484
]
5585
```
5686

57-
## Extending Data Generator with JavaScript
87+
Notice how the status field in the second example matches the query parameter.
88+
Mokapi understands the request context and generates appropriate data.
89+
90+
## Declarative Formats in Schema
91+
92+
Use standard OpenAPI formats to generate specific data types automatically.
93+
Mokapi recognizes these formats and produces realistic values:
94+
95+
| Format | Type | Example Output |
96+
|---------------|----------|-----------------------------------------------------------|
97+
| date | string | 2017-07-21 |
98+
| time | string | 17:32:28Z |
99+
| date-time | string | 2017-07-21T17:32:28Z |
100+
| email | string | shanellewehner@cruickshank.biz |
101+
| uuid | string | dd5742d1-82ad-4d42-8960-cb21bd02f3e7 |
102+
| uri | string | http://www.regionale-enable.info/virtual/portals/redefine |
103+
| password | string | w*YoR94jFL@X |
104+
| ipv4 | string | 68.244.174.93 |
105+
| {zip} {city} | string | 82910 San Jose |
58106

59-
Mokapi’s test data engine is highly extensible using JavaScript, allowing you to customize responses
60-
based on specific attributes. In the example below, a random value from a predefined list is assigned to the frequency attribute.
107+
### Example Schema
61108

62-
``` box=info
63-
It’s recommended to define possible values using an enum in your API specification. This allows Mokapi to randomly
64-
select a value from the list and clearly document all available options for your API users. This example demonstrates
65-
the flexibility Mokapi offers.
109+
```yaml
110+
schema:
111+
type: object
112+
properties:
113+
date:
114+
type: string
115+
format: date # 2017-07-21
116+
time:
117+
type: string
118+
format: date-time # 2017-07-21T17:32:28Z
119+
email:
120+
type: string
121+
format: email # demetrisdach@yost.org
122+
guid:
123+
type: string
124+
format: uuid # dd5742d1-82ad-4d42-8960-cb21bd02f3e7
66125
```
67126
127+
This declarative approach requires no JavaScript, just add the `format` field to your schema.
128+
129+
## Customize with JavaScript
130+
131+
For more control, extend Mokapi's data generator with JavaScript. This is useful
132+
when you need values from a specific list, complex patterns, or custom logic.
133+
134+
### Example: Custom Enum Values
135+
136+
Generate random values from a predefined list:
137+
68138
```javascript
69139
import { fake, findByName, ROOT_NAME } from 'mokapi/faker';
70140
@@ -81,12 +151,25 @@ export default function() {
81151
};
82152
```
83153

84-
## Scripting API Behavior
154+
Now any field named `frequency` will randomly return one of these values.
155+
156+
``` box=tip title="Best Practice: Use Enums in Spec"
157+
It's recommended to define possible values using `enum` in your OpenAPI
158+
specification. This allows Mokapi to randomly select from the list automatically
159+
and clearly documents all available options for API users. The JavaScript
160+
approach shown here demonstrates Mokapi's flexibility for cases where
161+
enum isn't suitable.
162+
```
163+
164+
## Full Response Control with Scripts
165+
166+
For complete control over API behavior, use Mokapi Scripts to customize
167+
responses, simulate errors, add delays, or implement complex logic.
168+
169+
### Example: Dynamic Time API
85170

86-
Mokapi Script allows you to customize API responses and simulate various behaviors, such as returning specific HTTP
87-
statuses or producing Kafka messages.
171+
Create an API that returns the current timestamp:
88172

89-
Example: A simple time API returning the current timestamp:
90173
```javascript tab=time.js
91174
import {on} from 'mokapi'
92175

@@ -123,34 +206,22 @@ paths:
123206
format: date-time
124207
```
125208
126-
## Declarative Test Data Definition
209+
This script intercepts requests to the `time` operation and returns the current
210+
timestamp instead of a static mock value.
127211

128-
If you prefer a declarative approach, Mokapi uses formats like dates, emails, or UUIDs directly in your schema:
212+
## Validate in the Dashboard
129213

130-
```yaml
131-
schema:
132-
type: object
133-
properties:
134-
date:
135-
type: string
136-
format: date # 2017-07-21
137-
time:
138-
type: string
139-
format: date-time # 2017-07-21T17:32:28Z
140-
email:
141-
type: string
142-
format: email # demetrisdach@yost.org
143-
guid:
144-
type: string
145-
format: uuid # dd5742d1-82ad-4d42-8960-cb21bd02f3e7
146-
```
214+
The Mokapi dashboard lets you:
215+
216+
- **Generate sample data:** See what Mokapi produces for your schemas
217+
- **Validate against spec:** Ensure mock data matches your OpenAPI definition
218+
- **Inspect requests:** View generated responses for different request parameters
219+
- **Test edge cases:** Verify your custom generators work as expected
220+
221+
Access the dashboard at `http://localhost:8080` when Mokapi is running.
147222

148-
## Test and Validate in the Dashboard
149-
In the dashboard, you can easily generate sample data and validate it against your API’s specification.
150-
This allows you to ensure your mock data matches the expected structure and behavior. The following chapter will
151-
guide you through the process in more detail.
223+
## What's Next?
152224

153-
## Next Steps
225+
Explore related topics to get more out of Mokapi's test data generation:
154226

155-
- [Using Mokapi's Dashboard](dashboard.md)
156-
- [Explore Mokapi Scripts](../javascript-api/overview.md)
227+
{{ card-grid key="cards" }}

0 commit comments

Comments
 (0)