Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
a3c71a2
improve redirect
marle3003 Apr 24, 2025
e8d7d9e
Merge remote-tracking branch 'origin/develop' into develop
marle3003 Apr 24, 2025
3986e6f
Bump ace-builds from 1.40.0 to 1.40.1 in /webui
dependabot[bot] Apr 25, 2025
d3ff2c8
Merge pull request #532 from marle3003/dependabot/npm_and_yarn/webui/…
github-actions[bot] Apr 25, 2025
4df7589
Bump vite from 6.3.2 to 6.3.3 in /webui
dependabot[bot] Apr 25, 2025
4c76d94
Merge pull request #533 from marle3003/dependabot/npm_and_yarn/webui/…
github-actions[bot] Apr 25, 2025
79f3a5e
Bump eslint from 9.24.0 to 9.25.1 in /webui
dependabot[bot] Apr 25, 2025
9f3894c
Merge pull request #534 from marle3003/dependabot/npm_and_yarn/webui/…
github-actions[bot] Apr 25, 2025
fc32bc7
Bump @types/node from 22.14.1 to 22.15.2 in /webui
dependabot[bot] Apr 25, 2025
c8f672e
Merge pull request #535 from marle3003/dependabot/npm_and_yarn/webui/…
github-actions[bot] Apr 25, 2025
c81b7ba
Bump vue-tsc from 2.2.8 to 2.2.10 in /webui
dependabot[bot] Apr 25, 2025
7516828
Merge pull request #536 from marle3003/dependabot/npm_and_yarn/webui/…
github-actions[bot] Apr 25, 2025
1786dc3
Bump github.com/evanw/esbuild from 0.25.2 to 0.25.3
dependabot[bot] Apr 25, 2025
e14fce1
Merge pull request #537 from marle3003/dependabot/go_modules/develop/…
github-actions[bot] Apr 25, 2025
4c79d1e
fix breadcrumb links
marle3003 Apr 25, 2025
c29538d
Merge remote-tracking branch 'origin/develop' into develop
marle3003 Apr 25, 2025
daa1e71
update htaccess for bots
marle3003 Apr 25, 2025
d1ac014
improve sitemap
marle3003 Apr 25, 2025
40ce6ab
improve search meta
marle3003 Apr 25, 2025
9714e75
improve search meta
marle3003 Apr 25, 2025
cef295a
fix test
marle3003 Apr 25, 2025
2e23d75
fix test
marle3003 Apr 25, 2025
1412bb9
fix markdown syntax error
marle3003 Apr 25, 2025
5d972fd
update redirect www to non-www
marle3003 Apr 26, 2025
6ce3353
add alt text
marle3003 Apr 26, 2025
8729017
improve meta title
marle3003 Apr 26, 2025
89fc29e
fix Kafka dashboard when multiple messages in a topic is defined
marle3003 Apr 27, 2025
d3be817
move webui blogs into resources
marle3003 Apr 27, 2025
1f79d8f
fix urls
marle3003 Apr 27, 2025
caeed67
add new blog article
marle3003 Apr 27, 2025
adb9d9c
update blog text
marle3003 Apr 27, 2025
cbec91e
fix links
marle3003 Apr 27, 2025
dfc8a9c
improve colors for light mode
marle3003 Apr 27, 2025
26e8b69
fix meta description length
marle3003 Apr 27, 2025
fef88f1
add webui index page for tutorials, examples and blogs
marle3003 Apr 28, 2025
6bce899
improve action logs for better debug UX
marle3003 Apr 28, 2025
3459595
add missing blog entry in mobile view
marle3003 Apr 28, 2025
c245266
Merge remote-tracking branch 'origin/develop' into develop
marle3003 Apr 28, 2025
acc03bf
improve webui view for action log
marle3003 Apr 28, 2025
b0da30e
add debugging blog article
marle3003 Apr 28, 2025
37ebac8
Merge branch 'main' into develop
marle3003 Apr 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ Explore tutorials that walk you through mocking different protocols and scenario
- [LDAP](https://mokapi.io/docs/guides/ldap/overview)
- [SMTP](https://mokapi.io/docs/guides/smtp/overview)
- [Javascript API](https://mokapi.io/docs/javascript-api)
- [Examples & Tutorials](https://mokapi.io/docs/resources)
- [Blogs](https://mokapi.io/docs/blogs)
- [Resources](https://mokapi.io/docs/resources)

# ☕ Support

Expand Down
6 changes: 6 additions & 0 deletions api/handler_schema_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"mokapi/schema/json/parser"
jsonSchema "mokapi/schema/json/schema"
"net/http"
"strings"
)

type validateRequest struct {
Expand Down Expand Up @@ -89,6 +90,11 @@ func parseByOpenApi(data []byte, s *schema.Schema, ct media.ContentType) (interf
var v interface{}
var err error
if ct.IsXml() {
str := strings.TrimSpace(string(data))
if !strings.HasPrefix(str, "<") {
return nil, fmt.Errorf("input does not appear to be valid XML")
}

v, err = schema.UnmarshalXML(bytes.NewReader(data), s)
if err != nil {
return v, err
Expand Down
17 changes: 17 additions & 0 deletions api/handler_schema_validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,23 @@ func TestHandler_Schema_Validate(t *testing.T) {
)
},
},
{
name: "validating xml but send json data",
app: &runtime.App{
Monitor: monitor.New(),
},
fn: func(t *testing.T, h http.Handler, app *runtime.App) {
try.Handler(t,
http.MethodGet,
"http://foo.api/api/schema/validate",
nil,
`{ "schema": {"type": ["object"], "properties": { "foo":{ "type": ["string"] } }, "xml": { "name": "root" } }, "data":"{\"foo\":\"bar\"}", "format": "application/vnd.oai.openapi;version=3.0.0", "contentType": "application/xml" }`,
h,
try.HasBody(`["input does not appear to be valid XML"]`),
try.HasStatusCode(400),
)
},
},
}

for _, tc := range testcases {
Expand Down
51 changes: 35 additions & 16 deletions docs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,20 @@
"component": "examples",
"hideNavigation": true,
"hideInNavigation": true,
"title": "Learn with Mokapi's tutorials & examples",
"description": "Learn how to get started with Mokapi and simulate APIs that don't even exist yet."
"canonical": "/docs/resources",
"title": "Explore Mokapi Resources: Tutorials, Examples, and Blog Articles",
"description": "Explore Mokapi's resources including tutorials, examples, and blog articles. Learn to mock APIs, validate schemas, and streamline your development."
},
"items": {
"Tutorials": {
"expanded": true,
"index": {
"component": "examples",
"hideNavigation": true,
"hideInNavigation": true,
"canonical": "/docs/resources",
"title": "Explore Mokapi Resources: Tutorials, Examples, and Blog Articles",
"description": "Explore Mokapi's resources including tutorials, examples, and blog articles. Learn to mock APIs, validate schemas, and streamline your development."
},
"items": {
"Get started with REST API": "resources/tutorials/simple-http-api.md",
"Mock OpenAPI Authentication API Key & Bearer Token": "resources/tutorials/mock-openapi-auth-apikey-bearer.md",
Expand All @@ -167,26 +175,37 @@
}
},
"Examples": {
"expanded": true,
"index": {
"component": "examples",
"hideNavigation": true,
"hideInNavigation": true,
"canonical": "/docs/resources",
"title": "Explore Mokapi Resources: Tutorials, Examples, and Blog Articles",
"description": "Explore Mokapi's resources including tutorials, examples, and blog articles. Learn to mock APIs, validate schemas, and streamline your development."
},
"items": {
"Mokapi behind Reverse Proxy": "resources/examples/mokapi-behind-proxy.md",
"Mokapi with custom base image": "resources/examples/mokapi-with-custom-base-image.md"
}
},
"Blogs": {
"index": {
"component": "examples",
"hideNavigation": true,
"hideInNavigation": true,
"canonical": "/docs/resources",
"title": "Explore Mokapi Resources: Tutorials, Examples, and Blog Articles",
"description": "Explore Mokapi's resources including tutorials, examples, and blog articles. Learn to mock APIs, validate schemas, and streamline your development."
},
"items": {
"Automation Testing in Agile Development": "resources/blogs/automation-testing-agile-development.md",
"Contract Testing": "resources/blogs/contract-testing.md",
"End to End Testing with Mocked APIs": "resources/blogs/end-to-end-testing-mocked-apis.md",
"Debugging Mokapi Scripts": "resources/blogs/debugging-mokapi-scripts.md"
}
}
}
},
"Blogs": {
"index": {
"component": "blogs",
"hideInNavigation": true,
"title": "Mocking and Testing",
"description": "Learn about API mocking and contract testing. Improve your development skills."
},
"items": {
"Automation Testing in Agile Development": "blogs/automation-testing-agile-development.md",
"Contract Testing": "blogs/contract-testing.md"
}
},
"References": {
"items": {
"Declarative Data": "references/declarative-data.md",
Expand Down
38 changes: 28 additions & 10 deletions docs/configuration/dynamic/overview.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
---
title: Configure your Mokapi with powerful providers
description: Mokapi gathers configurations and scripts via providers.
title: Configure your Mokapi with powerful configuration providers
description: Learn how Mokapi gathers configurations and scripts using powerful providers. Customize your API mocks dynamically for flexible testing and development.
---

# Providers
# What Is Dynamic Configuration?

Mokapi gathers configurations and scripts via providers.
Dynamic configuration in Mokapi allows you to modify mock services, API behaviors, and test scenarios
in real-time without restarting the application. This capability is essential for agile
development and continuous integration workflows, enabling rapid iteration and testing of various
API responses.

## Supported Providers
## Features

Below is the list of supported providers in Mokapi
- **Live Updates:** Modify configurations on-the-fly to simulate different API behaviors.
- **Multi-Source Support:** Load configurations from various sources such as files, HTTP endpoints, Git repositories, or NPM packages.
- **JavaScript Integration:** Utilize embedded JavaScript to define dynamic behaviors, including conditional responses and simulated delays.
- **Patch-Based Changes:** Apply changes using patch configurations, preserving the original contract while customizing behaviors.
- **Dashboard Monitoring:** Visualize and manage configurations through an intuitive web interface.​

- [File](/docs/configuration/dynamic/file.md)
- [HTTP](/docs/configuration/dynamic/http.md)
- [GIT](/docs/configuration/dynamic/git.md)
- [NPM](/docs/configuration/dynamic/npm.md)
## Configuration Sources

Mokapi supports multiple configuration sources, providing flexibility in how you manage and deploy your mock services:

- [**File System:**](/docs/configuration/dynamic/file.md) Store configurations locally for quick access and version control.
- [**HTTP:**](/docs/configuration/dynamic/http.md) Fetch configurations from remote servers, facilitating centralized management.
- [**Git:**](/docs/configuration/dynamic/git.md) Integrate with Git to leverage version control and collaborative workflows.
- [**NPM Packages:**](/docs/configuration/dynamic/npm.md) Distribute and manage configurations as NPM packages for consistency across projects.

## Best Practices

- **Use Version Control:** Store your configuration files in a version control system like Git to track changes and collaborate effectively.
- **Modularize Configurations:** Break down configurations into modular components for reusability and easier maintenance.
- **Validate Configurations:** Regularly validate your configurations to ensure they meet the expected schema and behavior.
- **Monitor Changes:** Utilize Mokapi's dashboard to monitor configuration changes and their impact on mock services.
4 changes: 2 additions & 2 deletions docs/configuration/introduction.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Introduction
description: This page will introduce you to the startup and dynamic configurations.
title: Introduction to Mokapi Configuration | Static & Dynamic Setup Explained
description: Discover how to configure Mokapi using static files or dynamic updates. Learn startup options, hot-reloading, and flexible setup for your mocked APIs.
---
# Introduction

Expand Down
4 changes: 2 additions & 2 deletions docs/guides/get-started/running.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Running Your First Mocked REST API
description: Learn how to mock a REST API and analyze HTTP request and response in the dashboard.
title: Running Your First Mocked REST API with Mokapi
description: Learn how to run your first mocked REST API using Mokapi. Monitor HTTP requests and responses in the dashboard—ideal for testing and debugging APIs.
---
# Running Your First Mocked REST API with Mokapi

Expand Down
4 changes: 2 additions & 2 deletions docs/guides/get-started/welcome.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "Getting Started with Mokapi: Mock APIs and Validate Against Schemas"
description: Learn to set up Mokapi for mocking APIs, no account required, free and open-source.
title: "Getting Started with Mokapi | Mock APIs & Validate with OpenAPI and AsyncAPI"
description: Learn how to set up Mokapi to mock APIs and validate requests using OpenAPI or AsyncAPI. No account needed—free, open-source, and easy to use.
cards:
items:
- title: Run your first mocked REST API
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/ldap/intro.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: How to mock LDAP with Mokapi
description: Integrate your App with a mock LDAP server
description: Learn how to mock and test LDAP authentication using Mokapi. Simulate user login, group permissions, and directory structure for development and testing.
cards:
items:
- title: Run your first mocked LDAP
Expand Down
4 changes: 2 additions & 2 deletions docs/javascript-api/mokapi-http/args.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Args
description: Args is an object used by functions in the module mokapi/http
title: Args Object | Mokapi HTTP Module Function Parameters
description: The Args object is used by functions in the Mokapi HTTP module to access request parameters, headers, body data, and more for API mocking logic.
---
# Args

Expand Down
4 changes: 2 additions & 2 deletions docs/javascript-api/mokapi-http/delete.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: del( url, [body], [args] )
description: Make an HTTP DELETE request
title: del( url, [body], [args] ) - Mock HTTP DELETE Requests with Mokapi JavaScript API
description: Use Mokapi's JavaScript API to mock HTTP DELETE requests. Customize responses, handle request data, and simulate APIs for testing and development.
---
# del( url, [body], [args] )

Expand Down
4 changes: 2 additions & 2 deletions docs/javascript-api/mokapi-http/get.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: get( url, [args] )
description: Make an HTTP GET request
title: get( url, [args] ) - Mock HTTP GET Requests with Mokapi JavaScript API
description: Use Mokapi's JavaScript API to mock HTTP GET requests. Customize responses, handle request data, and simulate APIs for testing and development.
---
# get( url, [args] )

Expand Down
4 changes: 2 additions & 2 deletions docs/javascript-api/mokapi-http/head.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: head( url, [args] )
description: Make an HTTP HEAD request
title: head( url, [args] ) - Mock HTTP HEAD Requests with Mokapi JavaScript API
description: Use Mokapi's JavaScript API to mock HTTP HEAD requests. Customize responses, handle request data, and simulate APIs for testing and development.
---
# head( url, [args] )

Expand Down
4 changes: 2 additions & 2 deletions docs/javascript-api/mokapi-http/httpresponse.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Response Object (mokapi/http)
description: Returned by HTTP request methods in module mokapi/http.
title: HTTP Response Object | Mokapi JavaScript API Reference (mokapi/http)
description: Learn about the HTTP Response object returned by Mokapi's HTTP request methods. Access status, headers, and body for API mocking and testing.
---
# Response

Expand Down
4 changes: 2 additions & 2 deletions docs/javascript-api/mokapi-http/options.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: options( url, [body], [args] )
description: Make an HTTP OPTIONS request
title: options( url, [body], [args] ) - Mock HTTP OPTIONS Requests with Mokapi JavaScript API
description: Use Mokapi's JavaScript API to mock HTTP OPTIONS requests. Customize responses, handle request data, and simulate APIs for testing and development.
---
# options( url, [body], [args] )

Expand Down
4 changes: 2 additions & 2 deletions docs/javascript-api/mokapi-http/patch.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: patch( url, [body], [args] )
description: Make an HTTP PATCH request
title: patch( url, [body], [args] ) - Mock HTTP PATCH Requests with Mokapi JavaScript API
description: Use Mokapi's JavaScript API to mock HTTP PATCH requests. Customize responses, handle request data, and simulate APIs for testing and development.
---
# patch( url, [body], [args] )

Expand Down
4 changes: 2 additions & 2 deletions docs/javascript-api/mokapi-http/post.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: post( url, [body], [args] )
description: Make an HTTP POST request
title: post( url, [body], [args] ) - Mock HTTP POST Requests with Mokapi JavaScript API
description: Use Mokapi's JavaScript API to mock HTTP POST requests. Customize responses, handle request data, and simulate APIs for testing and development.
---
# post( url, [body], [args] )

Expand Down
4 changes: 2 additions & 2 deletions docs/javascript-api/mokapi-http/put.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: put( url, [body], [args] )
description: Make an HTTP PUT request
title: put( url, [body], [args] ) - Mock HTTP PUT Requests with Mokapi JavaScript API
description: Use Mokapi's JavaScript API to mock HTTP PUT requests. Customize responses, handle request data, and simulate APIs for testing and development.
---
# put( url, [body], [args] )

Expand Down
86 changes: 86 additions & 0 deletions docs/resources/blogs/debugging-mokapi-scripts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
title: Debugging Mokapi JavaScript
description: Learn how to debug your JavaScript code inside Mokapi using console.log, console.error, and event handler tracing.
---

# Debugging Mokapi JavaScript

Mokapi makes it easy not only to mock APIs, LDAP servers, Kafka topics, and mail servers, but also to
customize behavior using JavaScript. To help you debug your JavaScript code inside Mokapi, it provides
simple but powerful tools: `console.log`, `console.error`, and advanced event handler tracing.

This article will walk you through how to effectively debug your JavaScript running in Mokapi.

## Console Output: `console.log` and `console.error`

Mokapi provides the familiar `console.log` and `console.error` functions that you know from the browser or Node.js.
These functions write directly to the Mokapi console output.

Use `console.log` to output general debug information:
```javascript
console.log('Hello World');
```

Use `console.error` to report errors or unexpected behavior:
```javascript
console.error({ firstname:"John", lastname:"Doe" });
```

Everything you log will appear in the terminal or system where you run Mokapi, making
it easy to follow what your scripts are doing behind the scenes.

``` box=tip
There is also a function console.warn and console.debug
```

## Event Handler Tracing

Sometimes you need even deeper insights into how Mokapi processes a request — especially when you
are using event handlers to customize behavior.

If your event handler function returns `true`, Mokapi not only executes the event but also:

- Logs the event handler data such as file, event type, event parameters
- Displays it in the Mokapi Dashboard under the request details

This makes it very easy to see which handlers were involved in a request and in what order.

Here's an example:
```javascript
import { on } from 'mokapi';

export default () => {
on("http", (req, res) => {
console.log("Handling request for:", req.path);

if (req.path.startsWith("/admin")) {
console.log("Admin path detected");
return true; // Trace this handler
}
return false;
});
}
```

In this case, because the handler returns true, Mokapi will:

- Log that the onRequest handler was triggered
- List the handler in the dashboard under the request details

This visibility is incredibly helpful when debugging complex request flows, especially if you have
multiple handlers reacting to a single request.

## Best Practices for Debugging

- Use console.log freely during development to trace values and decisions inside your scripts.
- Return true from important event handlers you want to trace in the dashboard.
- Use console.error for anything unexpected to separate normal logs from problems.
- Check the Dashboard for a clear overview of all event handlers triggered by a request.

## Conclusion

Debugging Mokapi JavaScript is straightforward with console.log, console.error, and event handler
tracing. Whether you're building complex mock logic or just getting started, these tools will help you
understand exactly what happens inside Mokapi when it processes your requests.

Give it a try — and happy debugging!
Loading
Loading