APIGit
Native Git RepositoryVersioned, Git-native API repositoryAPI DesignVisual OpenAPI editor with live lintingAPI DocumentPublish versioned docs from GitAPI GovernanceCheck every API against your standardsMock ServerFrom your OpenAPI spec or Express.js codeTeam CollaborationOrganizations, teams, permissions and reviews

The full API lifecycle

Design, document, mock and govern your APIs in one Git-native workspace.

Get started freeView pricing

Learning

Help DocsGetting StartedVideo TutorialsBlog

Support

Contact UsRequest a DemoReport an Issue
PricingAbout
Sign InSign Up for Free
APIGit

The Git Platform for Full Life-Cycle API Development

Product

  • Native Git Repository
  • API Design
  • API Document
  • API Governance
  • Mock Server
  • Team Collaboration

Resources

  • Blog
  • Documentation
  • Pricing
  • Contact

Company

  • About
  • Careers
  • Privacy Policy
  • Terms of Service
  • Service Level Agreement
  • Cookie Policy

© 2026 APIGit. All rights reserved.

Home / Blog / mock-server / spec-based-or-code-based-mock-server

Spec-Based or Code-Based: Which Mock Server Do You Need?

2026-11-06
APIGit Team
4 min read
mock-server

APIGit has two types of mock server. Every mock server is one or the other, and you choose when you publish it. The short answer is to start with spec-based. Here is how to tell when you need code.

The difference

| | Spec-based | Code-based | |---|---|---| | Source | One or more OpenAPI documents | Scripts in apigit-mock/ | | You write | Nothing beyond the document | JavaScript (Express.js) | | Responses | Examples from the document, or generated from its schemas | Whatever your code returns | | Request validation | Built in, and configurable | Your own code | | Stays in step with the spec | Always: the document is the mock | Up to you | | State between requests | No | Yes, with the state object | | Plans | Free, Team, Enterprise | Team, Enterprise |

Choose spec-based when the document says enough

If your API is described in OpenAPI, a spec-based mock gives you a working, validating server in about a minute, and it cannot drift from the spec. It suits frontend teams building against an API that does not exist yet, and partners who need a sandbox. Declared errors are one header away: Prefer: code=404.

Choose code-based when answers depend on something

Choose code-based when a response must depend on earlier requests, or on logic the document cannot express: a multi-step checkout, an OAuth flow, a computed price.

A code-based mock runs the scripts in your repository's apigit-mock/ folder. mock is an Express.js 4 app, so you get mock.get(), mock.post(), mock.use() and the rest of the Express API, and state persists between requests:

apigit-mock/main.js
mock.post('/users', (req, res) => {
  state.users = state.users || [];
  state.users.push(req.body);
  res.status(201).json({ count: state.users.length });
});

Libraries such as @faker-js/faker, lodash and jsonwebtoken are pre-installed. Your code runs in an isolated sandbox with no network access, so it cannot call outside services. The apigit-mock/ folder can be 2 MiB zipped, and state can be 2 MB. You do not have to start from nothing: Generate from Spec in the Mock Scripts tab writes routes from an API document, and the code is yours from then on.

Publish dialog of a code-based mock server

You can have both

The type belongs to each mock server, not to the repository. One repository can publish several mock servers of either type, from the same commit or from different ones: a spec-based mock of openapi/petstore.yaml for the frontend team, and a code-based mock of a stateful checkout flow, side by side.

Mock servers of a repository in the Publish Center

A mock server keeps its type when you overwrite it. To change type, publish a new mock server. Each mock has its own URL, so you can run both while clients move. Moving from code to spec usually means adding example values to your document for the responses your scripts returned.

What each plan includes

| | Free | Team | Enterprise | |---|---|---|---| | Mock servers | 1 | 10 per seat | 20 per seat | | Mock server calls per month | 1,000 | 2,000 per seat | 4,000 per seat | | Documents per spec-based mock | 1 | 10 | 10 | | Code-based mock servers | No | Yes | Yes |

Read more in the Mock Server overview and How code-based mocks work.

Back to Blog

Related Posts

Spec-Based Mock Servers: A Working Mock from Your OpenAPI Document

APIGit • 2026-11-06
mock-server

Publish a mock server from your OpenAPI documents without writing code. It validates requests, answers from your examples and schemas, and works on every plan.

Read More

Mock Servers That Tell You What Is Wrong

APIGit • 2026-11-06
mock-server

Spec-based mock servers validate each request against your OpenAPI document, return clear problem+json errors, and let clients pick a response with the Prefer header.

Read More

Pin or Follow a Branch: Mock Servers and Published Documents

APIGit • 2026-11-06
mock-server

Keep a mock server or a document on one commit, or let it follow a branch. Run several versions from one commit, such as a pinned 2.1 next to a following next.

Read More

Ready to get started with APIGIT?

Join thousands of developers and teams who are already using APIGIT to streamline their API development workflow.

Get Started Book a Demo