You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This starts a mock server immediately without permanent installation. Perfect for quick tests and demos.
38
+
````
11
39
12
40
## Installation Options
13
41
@@ -16,23 +44,39 @@ Choose your preferred method below:
16
44
17
45
::: tabs
18
46
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
+
19
58
@tab "macOS"
20
59
21
60
### Homebrew
22
61
62
+
Install via Homebrew for easy updates and management:
63
+
23
64
```bash
24
65
brew tap marle3003/tap
25
66
brew install mokapi
26
67
```
27
68
28
69
### Direct Download
29
70
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.
31
73
32
74
@tab "Windows"
33
75
34
76
### Chocolatey
35
77
78
+
Install via Chocolatey for easy updates:
79
+
36
80
```Powershell
37
81
choco install mokapi
38
82
```
@@ -43,6 +87,8 @@ Download the latest Windows version from [GitHub](https://github.com/marle3003/m
43
87
44
88
@tab "Linux"
45
89
90
+
Download the .deb package from the releases page and install:
91
+
46
92
### Direct Download
47
93
48
94
Download file appropriate for your Linux distribution and ARCH from the [release page](https://github.com/marle3003/mokapi/releases), then install with
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):
62
107
63
108
```
64
109
docker pull mokapi/mokapi
65
110
```
66
111
67
-
@tab "NPM"
112
+
:::
68
113
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:
71
116
72
-
```bash
73
-
npm install -g go-mokapi
117
+
```bash style=simple
118
+
mokapi --version
74
119
```
75
120
76
-
:::
121
+
````
77
122
78
-
### Mokapi Scripts Type Definitions
123
+
##TypeScript Support
79
124
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:
82
126
83
127
```bash
84
128
npm install --save-dev @types/mokapi
85
129
```
86
130
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
+
exportdefaultfunction() {
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:
88
155
89
-
-[Create your first Mock](/docs/get-started/running.md)
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
4
19
---
5
20
6
-
# Mocking APIs with Realistic Test Data
21
+
# Generate Realistic Test Data
7
22
8
23
Creating reliable test data is essential for accurate API testing and development.
9
24
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
12
37
13
38
## Automatic Test Data Generation
14
39
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":
18
48
19
-
```bash tab=/pet/4
49
+
```bash tab=Single Pet
20
50
GET http://localhost/api/v3/pet/4
21
51
HTTP/1.1 200 OK
22
52
Content-Type: application/json
@@ -39,7 +69,7 @@ Content-Type: application/json
39
69
"status": "pending"
40
70
}
41
71
```
42
-
```bash tab=/pet/findByStatus
72
+
```bash tab=Filtered List
43
73
GET http://localhost/api/v3/pet/findByStatus?status=available
0 commit comments