[PR #5482] [MERGED] feature: mock server #5232

Closed
opened 2026-03-17 02:42:01 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/hoppscotch/hoppscotch/pull/5482
Author: @mirarifhasan
Created: 10/13/2025
Status: Merged
Merged: 10/27/2025
Merged by: @jamesgeorge007

Base: nextHead: mock-server


📝 Commits (10+)

  • 8bcf3fd feat: add mock server (#5385)
  • 1a43636 feat: implement MockServer migration and update GraphQL queries/mutations to use collection ID
  • 0b17b99 refactor: mock server to support user and team workspaces
  • 556d1bb refactor: mock server routing and add mockExamples sync
  • 3b50bdc feat: mock request handling and matching
  • 6d1db3e feat: update GraphQL mutations and queries to include workspace details and remove user field
  • 5a318fb feat: enhance MockServer types and queries to support workspace details and improve backward compatibility
  • 9a3d602 feat: enhance createMockServer function to include workspace type and visibility options
  • a6dc91c feat: update createMockServer mutation to use WorkspaceType enum for workspaceType
  • 950bfd3 feat: add mockExamples field to user and team request test data

📊 Changes

59 files changed (+6249 additions, -69 deletions)

View changed files

📝 aio-multiport-setup.Caddyfile (+12 -1)
📝 aio-subpath-access.Caddyfile (+12 -1)
📝 packages/hoppscotch-backend/backend.Caddyfile (+12 -1)
packages/hoppscotch-backend/prisma/migrations/20251016080714_mock_server/migration.sql (+142 -0)
📝 packages/hoppscotch-backend/prisma/schema.prisma (+127 -59)
📝 packages/hoppscotch-backend/src/app.module.ts (+2 -0)
📝 packages/hoppscotch-backend/src/errors.ts (+49 -0)
📝 packages/hoppscotch-backend/src/gql-schema.ts (+2 -0)
📝 packages/hoppscotch-backend/src/infra-config/helper.ts (+5 -0)
📝 packages/hoppscotch-backend/src/infra-config/infra-config.service.ts (+11 -0)
packages/hoppscotch-backend/src/mock-server/mock-request.guard.ts (+274 -0)
packages/hoppscotch-backend/src/mock-server/mock-server-analytics.service.ts (+43 -0)
packages/hoppscotch-backend/src/mock-server/mock-server-logging.interceptor.ts (+169 -0)
packages/hoppscotch-backend/src/mock-server/mock-server.controller.ts (+124 -0)
packages/hoppscotch-backend/src/mock-server/mock-server.model.ts (+294 -0)
packages/hoppscotch-backend/src/mock-server/mock-server.module.ts (+22 -0)
packages/hoppscotch-backend/src/mock-server/mock-server.resolver.ts (+222 -0)
packages/hoppscotch-backend/src/mock-server/mock-server.service.spec.ts (+1157 -0)
packages/hoppscotch-backend/src/mock-server/mock-server.service.ts (+1043 -0)
📝 packages/hoppscotch-backend/src/orchestration/sort/sort.service.spec.ts (+1 -1)

...and 39 more files

📄 Description

Closes BE-659

Related to #1598.

What's changed

This PR introduces a mock server feature that enables users to create and manage API mock servers based on their collections. The mock servers can simulate API responses using example data stored in collections, supporting both user and team workspaces with subdomain-based and path-based routing patterns.

Screenshot 2025-10-17 at 2 31 17 PM

Key changes:

  • Backend infrastructure for mock server management (CRUD operations, request handling, logging, and analytics)
  • Frontend UI for creating and configuring mock servers
  • Database schema additions for mock servers, logs, and activity tracking
  • Support for both public and private (PAT-authenticated) mock servers

Backend Changes

Mock Server can be created, updated, and deleted (soft delete) via GQL mutations for both Personal and Team workspaces

mutation createMockServer
mutation updateMockServer
mutation deleteMockServer

Following queries to view mock servers. All have access permission checks.

query myMockServers # Logged-in user's mock servers
query teamMockServers # Selected team's mock servers
query mockServer # Get mock server by ID

You can see the mock server's request logs

query mockServerLogs
mutation deleteMockServerLog

For analytics purposes

  • We count the number of incoming requests
  • Events (CREATED, ACTIVE, INACTIVE, DELETED) to further use of showing how long the mock server has been active for the future (not in this release). Just implemented in the backend in advance.

Notes to reviewers

  1. Run DB migration
  2. Test mock server functionality

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/hoppscotch/hoppscotch/pull/5482 **Author:** [@mirarifhasan](https://github.com/mirarifhasan) **Created:** 10/13/2025 **Status:** ✅ Merged **Merged:** 10/27/2025 **Merged by:** [@jamesgeorge007](https://github.com/jamesgeorge007) **Base:** `next` ← **Head:** `mock-server` --- ### 📝 Commits (10+) - [`8bcf3fd`](https://github.com/hoppscotch/hoppscotch/commit/8bcf3fd53384d87530968e443e93a9b671074601) feat: add mock server (#5385) - [`1a43636`](https://github.com/hoppscotch/hoppscotch/commit/1a43636e02930c9868b61d4f842c59f347b5eb83) feat: implement MockServer migration and update GraphQL queries/mutations to use collection ID - [`0b17b99`](https://github.com/hoppscotch/hoppscotch/commit/0b17b99382e126ce3e0b010f9477d47c4f82a72e) refactor: mock server to support user and team workspaces - [`556d1bb`](https://github.com/hoppscotch/hoppscotch/commit/556d1bb3f10bbd3f51c18daedadfcf8b048be536) refactor: mock server routing and add mockExamples sync - [`3b50bdc`](https://github.com/hoppscotch/hoppscotch/commit/3b50bdcd0fb28dfac132747819e32547ee131e54) feat: mock request handling and matching - [`6d1db3e`](https://github.com/hoppscotch/hoppscotch/commit/6d1db3ed16fe5f9b5bb9966d3c78ca859e3dedff) feat: update GraphQL mutations and queries to include workspace details and remove user field - [`5a318fb`](https://github.com/hoppscotch/hoppscotch/commit/5a318fbc884b9349de5972f870b91fd9f979bd09) feat: enhance MockServer types and queries to support workspace details and improve backward compatibility - [`9a3d602`](https://github.com/hoppscotch/hoppscotch/commit/9a3d60283b75954a739245a554c5aa9c79856c87) feat: enhance createMockServer function to include workspace type and visibility options - [`a6dc91c`](https://github.com/hoppscotch/hoppscotch/commit/a6dc91c6fc6a45cb9aba1be2747c26943220f982) feat: update createMockServer mutation to use WorkspaceType enum for workspaceType - [`950bfd3`](https://github.com/hoppscotch/hoppscotch/commit/950bfd3b1473bdb9418ac46c76f1b435cc9a7a05) feat: add mockExamples field to user and team request test data ### 📊 Changes **59 files changed** (+6249 additions, -69 deletions) <details> <summary>View changed files</summary> 📝 `aio-multiport-setup.Caddyfile` (+12 -1) 📝 `aio-subpath-access.Caddyfile` (+12 -1) 📝 `packages/hoppscotch-backend/backend.Caddyfile` (+12 -1) ➕ `packages/hoppscotch-backend/prisma/migrations/20251016080714_mock_server/migration.sql` (+142 -0) 📝 `packages/hoppscotch-backend/prisma/schema.prisma` (+127 -59) 📝 `packages/hoppscotch-backend/src/app.module.ts` (+2 -0) 📝 `packages/hoppscotch-backend/src/errors.ts` (+49 -0) 📝 `packages/hoppscotch-backend/src/gql-schema.ts` (+2 -0) 📝 `packages/hoppscotch-backend/src/infra-config/helper.ts` (+5 -0) 📝 `packages/hoppscotch-backend/src/infra-config/infra-config.service.ts` (+11 -0) ➕ `packages/hoppscotch-backend/src/mock-server/mock-request.guard.ts` (+274 -0) ➕ `packages/hoppscotch-backend/src/mock-server/mock-server-analytics.service.ts` (+43 -0) ➕ `packages/hoppscotch-backend/src/mock-server/mock-server-logging.interceptor.ts` (+169 -0) ➕ `packages/hoppscotch-backend/src/mock-server/mock-server.controller.ts` (+124 -0) ➕ `packages/hoppscotch-backend/src/mock-server/mock-server.model.ts` (+294 -0) ➕ `packages/hoppscotch-backend/src/mock-server/mock-server.module.ts` (+22 -0) ➕ `packages/hoppscotch-backend/src/mock-server/mock-server.resolver.ts` (+222 -0) ➕ `packages/hoppscotch-backend/src/mock-server/mock-server.service.spec.ts` (+1157 -0) ➕ `packages/hoppscotch-backend/src/mock-server/mock-server.service.ts` (+1043 -0) 📝 `packages/hoppscotch-backend/src/orchestration/sort/sort.service.spec.ts` (+1 -1) _...and 39 more files_ </details> ### 📄 Description <!-- Thanks for creating this pull request 🤗 Please make sure that the pull request is limited to one type (docs, feature, etc.) and keep it as small as possible. You can open multiple prs instead of opening a huge one. --> <!-- If this pull request closes an issue, please mention the issue number below --> <!-- Issue # here --> Closes BE-659 Related to #1598. <!-- Add an introduction into what this PR tries to solve in a couple of sentences --> ### What's changed <!-- Describe point by point the different things you have changed in this PR --> This PR introduces a mock server feature that enables users to create and manage API mock servers based on their collections. The mock servers can simulate API responses using example data stored in collections, supporting both user and team workspaces with subdomain-based and path-based routing patterns. <img width="800" height="543" alt="Screenshot 2025-10-17 at 2 31 17 PM" src="https://github.com/user-attachments/assets/12df2289-6234-4322-ba4e-f3732de59d51" /> Key changes: - Backend infrastructure for mock server management (CRUD operations, request handling, logging, and analytics) - Frontend UI for creating and configuring mock servers - Database schema additions for mock servers, logs, and activity tracking - Support for both public and private (PAT-authenticated) mock servers #### Backend Changes Mock Server can be created, updated, and deleted (soft delete) via GQL mutations for both Personal and Team workspaces ```gql mutation createMockServer mutation updateMockServer mutation deleteMockServer ``` Following queries to view mock servers. All have access permission checks. ```gql query myMockServers # Logged-in user's mock servers query teamMockServers # Selected team's mock servers query mockServer # Get mock server by ID ``` You can see the mock server's request logs ```gql query mockServerLogs mutation deleteMockServerLog ``` For analytics purposes - We count the number of incoming requests - Events (CREATED, ACTIVE, INACTIVE, DELETED) to further use of showing how long the mock server has been active for the future (not in this release). Just implemented in the backend in advance. <!-- You can also choose to add a list of changes and if they have been completed or not by using the markdown to-do list syntax - [ ] Not Completed - [x] Completed --> ### Notes to reviewers <!-- Any information you feel the reviewer should know about when reviewing your PR --> 1. Run DB migration 2. Test mock server functionality --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-17 02:42:01 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hoppscotch#5232
No description provided.