Skip to content

About

Turn an OpenAPI spec into a local API in one command. Build and test your frontend with custom responses, shared state, and simulated failures, without waiting for the backend.

Topics

Resources

Code of conduct

Contributing

Security policy

Accessibility

Stars

170 stars

Watchers

4 watching

Forks

Latest commit

 

History

5,401 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Counterfact

Build the frontend. Don’t wait for the backend.

Counterfact lets frontend developers work independently of the backend. People and agents can build and test against an API contract instead of a live API, simulating new functionality, error responses, and edge cases. Selectively proxy requests to real services when they are useful.

The backend isn’t ready

Frontend work shouldn’t have to wait for the backend. When an API is unavailable or a feature hasn’t been built yet, developers still need a way to build and test the clients that depend on it.

Web and mobile clients send API requests to an unavailable backend and wait for responses.

Counterfact implements the contract

Give Counterfact an OpenAPI contract, and it provides a working API for your web and mobile clients. Develop against that contract, simulate new functionality, and test errors and edge cases without waiting for the live backend.

Web and mobile clients build and test against Counterfact’s simulated responses. An OpenAPI contract specifies the interface; the backend remains unavailable.

Mix simulated and real responses

Web and mobile clients use the same Counterfact interface. Counterfact simulates responses and proxies selected requests to available real services. The OpenAPI contract specifies the interface.

The OpenAPI document describes the interface. Counterfact handles requests and returns simulated responses or forwards selected requests to a real service.

Try it

With Node.js 22 or newer, run this example in a new directory:

npx counterfact@latest https://petstore3.swagger.io/api/v3/openapi.json api

Counterfact creates editable routes and generated types in api/, then starts a local API at http://localhost:3100. Try http://localhost:3100/pet/1 or open Swagger UI. Generated sample responses are a starting point; customize the behavior your frontend needs.

Use your own OpenAPI document in place of the example URL. For a repeatable project or CI workflow, install a pinned version and commit the lockfile.

Keep going

This is a Yarn workspace monorepo. The published application and canonical user docs live in packages/counterfact. Focused packages: client, generator, OpenAPI, REPL, runtime, and types.

MIT license · Copyright Patrick McElhaney.

About

Turn an OpenAPI spec into a local API in one command. Build and test your frontend with custom responses, shared state, and simulated failures, without waiting for the backend.

Topics

Resources

Code of conduct

Contributing

Security policy

Accessibility

Stars

170 stars

Watchers

4 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages