https://github.com/wiremock/wiremock-extension-template
A template project for those who want to create a new WireMock extension/plugin
https://github.com/wiremock/wiremock-extension-template
hacktoberfest template wiremock wiremock-extension
Last synced: 10 months ago
JSON representation
A template project for those who want to create a new WireMock extension/plugin
- Host: GitHub
- URL: https://github.com/wiremock/wiremock-extension-template
- Owner: wiremock
- License: apache-2.0
- Created: 2023-10-09T08:06:36.000Z (over 2 years ago)
- Default Branch: develop
- Last Pushed: 2024-01-12T20:09:31.000Z (over 2 years ago)
- Last Synced: 2025-04-14T17:56:22.060Z (about 1 year ago)
- Topics: hacktoberfest, template, wiremock, wiremock-extension
- Language: Java
- Homepage: https://wiremock.org/docs/extending-wiremock/
- Size: 75.2 KB
- Stars: 6
- Watchers: 4
- Forks: 1
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# WireMock extension template
Template for creating new WireMock extensions.
# Template usage
This template contains various samples on how you can write your own extension - just clone it and get started.
Not all parts are needed, thus feel free to adapt it. The code is documented and marked with `TODO` comments to help
finding customization points.
# Manuals
## Overall extension documentation
Extensions can be explicitly configured or auto-detected. This extension supports auto-detection which eases integration
in [WireMock standalone](https://wiremock.org/docs/standalone/java-jar/) or [docker containers](https://wiremock.org/docs/standalone/docker/).
For supporting auto-detection as standalone library, this template implements the
[Java Service Provider Interface](https://docs.oracle.com/javase/tutorial/sound/SPI-intro.html), which is used by WireMock
to find extensions and packages everything using shadowjar.
When forking this repository, you have to adapt `shadowjar/resources/META-INF/services/com.github.tomakehurst.wiremock.extension.ExtensionFactory`
to point to a class with default constructor which registers all parts of your extension
(in this template, this is handled by `org.wiremock.extensions.template.StandaloneTemplateExtension`).
For non-standalone usages, you can use your own class to instantiate your extension. In this template,
this is handled by `org.wiremock.extensions.template.TemplateExtension`. Having the standalone version using this one
helps ensuring a consistent extension setup.
## Request matcher
Official documentation on using request matchers: https://wiremock.org/docs/request-matching/
Official documentation on creating request matchers extension: https://wiremock.org/docs/extensibility/custom-matching/
The sample code in this template shows how to read parameters and values which contain [handlebar templates](https://handlebarsjs.com)
to get similar functionalities as when using them in [response templates](https://wiremock.org/docs/response-templating/).
See `org.wiremock.extensions.template.extensions.RequestMatcher` for a sample and `org.wiremock.extensions.template.RequestMatcherTest`
for a corresponding test.