# Mock the API

Source: https://api-genie.dev/docs/guides/editor/mock-the-api

The desktop app and the VS Code extension start `apigenie-server` on the spec you are editing,
and keep it in step with your edits. A client, or Try it out, gets the responses the spec
describes while the real server is still being written.

## Start the mock

Install [`apigenie-server`](/docs/reference/server), 0.11.0 or later, and select an OpenAPI
spec. *Mock server* in the toolbar starts it on `127.0.0.1`, on a free port. The toolbar then
says *Mock of <file>: <url> (n operations)*, with *Copy URL*, *Log (n)*, *Mock <other file>
instead* while another spec is selected, and *Stop mock*. In VS Code, the `apigenie.serverPath`
setting names the executable when it is not on the `PATH`.

The server gets the current text, saved or not, with the files the spec refers to inlined, shortly
after you stop typing. When the server refuses a version, it keeps the previous one, and the status
bar says so.

In the web editor the button is disabled, because a page cannot start a program; its tooltip
says where the mock server runs.

## Example or generated responses

The mock answers with the examples of each response. Tick *Generated* to get responses made
from the schemas instead, as `apigenie-server --dynamic` does, which exercises a client against
values it did not see in the examples. A running server starts again with the new choice.

## The log

*Log (n)* opens the server's log under the toolbar: each request with its method and path, what
the server answered or found wrong with it, and each reload that failed. The panel
keeps the last two hundred entries; *Clear* empties it and *Close* hides it. *No requests yet.
Send one to the URL above, or use Try it out in the preview* is what an idle server shows.

## Send Try it out to the mock

While the mock serves the spec, the preview of each operation says *The mock server serves this
spec at <url>*, with a button that sends Try it out there instead of the spec's servers, and *Use
the spec's servers* to go back. Nothing changes in the spec: the switch is the editor's.

## Responses you save

*Save as mock response* under a response of Try it out writes a scenario to the
[configuration of `apigenie-server`](/docs/reference/server/configuration), as
[Try it out](/docs/guides/editor/try-it-out#save-a-response) describes. The configuration is
read by `apigenie-server` when you run it yourself in the spec's folder; the toolbar's mock
server does not read it, and answers from the spec alone.

## Next

[Use Git](/docs/guides/editor/use-git) commits the spec from the editor.
[`apigenie-server`](/docs/reference/server) in the reference has every option of the mock.
