WireMock
IntelliJ IDEA provides support for WireMock, a tool for stubbing HTTP services. Stubbing involves creating stubs or set responses to API calls that mimic real API behavior without the need for actual server communication.
This functionality relies on the WireMock plugin, which you need to install and enable.
note
The WireMock plugin is not available in IntelliJ IDEA Community Edition.
Press CtrlAlt0S to open settings and then select Plugins.
Open the Marketplace tab, find the WireMock plugin, and click Install (restart the IDE if prompted).
If a JSON file is placed in the mappings folder or contains the "mappings"
key, IntelliJ IDEA recognizes it as a WireMock stub file and provides appropriate coding assistance.
In the Project tool window, right-click a folder (or press AltInsert) and select New | File.
In the New File dialog that opens, enter a name of the file. For example, you can enter
mappings/my-stub.json
, and IntelliJ IDEA will create the mappings folder and place the new file within it.Start typing a key to get suggestions for applicable keys and their quick documentation.
Open the Endpoints tool window (View | Tool Windows | Endpoints).
Right-click an endpoint and select Generate WireMock Stubs.
The new stub file is saved as a scratch under Scratches and Consoles | WireMock Stubs.
Open an OpenAPI specification file.
Click and select Generate WireMock Stubs.
The new stub file is saved as a scratch under Scratches and Consoles | WireMock Stubs.
Open your stub file.
Click in the upper-right part of the editor.
This will start the WireMock server, and you can see it running in the Services tool window (View | Tool Windows | Services or press Alt08).
To customize how IntelliJ IDEA starts the WireMock server, you can modify the WireMock run configuration or create a new one.
Use the IntelliJ IDEA HTTP Client to send HTTP request to the WireMock server and preview responses.
Open your stub JSON file.
Place the caret at your endpoint URL, press AltEnter (Show Context Actions), and select Generate request in HTTP Client.
You can view the stub response in the Services tool window.
IntelliJ IDEA provides coding assistance for templating language used in WireMock response templates. To use this feature, you need the Handlebars/Mustache plugin to be installed and enabled.
Open your stub JSON file.
In the upper-right part of the editor, click (Use Handlebars Templates). If the Handlebars/Mustache plugin is not installed, the action will install it.
This will make IntelliJ IDEA treat JSON files placed in the __files
directory as response templates and provide appropriate Handlebars coding assistance including completion for Handlebars helpers.
Create: Run | Edit Configurations | | WireMock
IntelliJ IDEA comes with a dedicated WireMock run configuration, which allows you to customize how to start the WireMock server.
- Enable global Handlebars templating
Render all response definitions using Handlebars templates by passing the
--global-response-templating
Wiremock command line option.
Specify which log files generated while running the application should be displayed in the console on the dedicated tabs of the Run tool window.
Select tasks to be performed before starting the selected run/debug configuration.
Thanks for your feedback!