{"id":20442596,"url":"https://github.com/masonm/wiremock-jsextend","last_synced_at":"2026-07-17T17:31:46.362Z","repository":{"id":146551429,"uuid":"96515038","full_name":"MasonM/wiremock-jsextend","owner":"MasonM","description":null,"archived":false,"fork":false,"pushed_at":"2017-07-31T02:57:27.000Z","size":60,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-24T13:42:41.993Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MasonM.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-07T08:05:06.000Z","updated_at":"2018-04-03T12:51:44.000Z","dependencies_parsed_at":"2023-06-04T20:00:29.918Z","dependency_job_id":null,"html_url":"https://github.com/MasonM/wiremock-jsextend","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/MasonM/wiremock-jsextend","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MasonM%2Fwiremock-jsextend","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MasonM%2Fwiremock-jsextend/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MasonM%2Fwiremock-jsextend/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MasonM%2Fwiremock-jsextend/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MasonM","download_url":"https://codeload.github.com/MasonM/wiremock-jsextend/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MasonM%2Fwiremock-jsextend/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35590613,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-17T02:00:06.162Z","response_time":116,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-15T09:41:44.021Z","updated_at":"2026-07-17T17:31:46.316Z","avatar_url":"https://github.com/MasonM.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Overview\n\nwiremock-jsextend is a \"meta-extension\" for [WireMock](http://wiremock.org) that lets you create and manage extensions written in Javascript using the [Nashorn JavaScript engine](http://www.n-k.de/riding-the-nashorn/) (with a fallback to Rhino for Java 7). It adds API endpoints to create, list, edit, and delete extensions. Example:\n\n```sh\n# Stub mapping for testing\n$ curl -s -d '{\n    \"request\": { \"url\": \"/test\" },\n    \"response\": { \"body\": \"TESTING\" }\n}' http://localhost:8080/__admin/mappings \u003e /dev/null\n\n# Test mapping\n$ curl -s http://localhost:8080/test\nTESTING\n\n# Create response transformer\n$ curl -s -d '\n    function transform(request, response) {\n        return Response.Builder\n            .like(response)\n            .but()\n            .body(response.getBodyAsString() + \", and transformed!\")\n            .build();\n   }\n' http://localhost:8080/__admin/extensions/response-transformer \u003e /dev/null\n\n# Test transformer\n$ curl -s http://localhost:8080/test\nTESTING, and transformed!\n```\n\n# Caveats/Limitations\n\n* This extension allows arbitrary code execution. **Do not use this unless you fully understand the security implications.**\n* `AdminApiExtension` and `PostServeAction` extensions are not supported.\n* Due to limitations in Wiremock, transformer extensions are always global. Transformer parameters can be used as a workaround.\n* Due to limitations in Wiremock, you cannot name request matcher extensions. See the [Request Matching](#request-matching) section below.\n* No load testing has been done yet, so I have no idea how well this will work with a large number of requests.\n\n# Building\n\nRun `gradle jar` to build the JAR without dependencies or `gradle fatJar` to build a standalone JAR.\nThese will be placed in `build/libs/`.\n\n# Running\n\nStandalone server:\n```sh\njava -jar build/libs/wiremock-jsextend-0.1a-standalone.jar\n```\n\nWith WireMock standalone JAR:\n```sh\njava \\\n        -cp wiremock-standalone.jar:build/libs/wiremock-snapshot-0.3a.jar \\\n        com.github.tomakehurst.wiremock.standalone.WireMockServerRunner \\\n        --extensions=\"com.github.masonm.wiremock.extension.JsExtendApiExtension,com.github.masonm.wiremock.extension.CompositeRequestMatcherExtension,com.github.masonm.wiremock.extension.CompositeResponseDefinitionTransformer,com.github.masonm.wiremock.extension.CompositeResponseTransformer,com.github.masonm.wiremock.extension.JsExtendStubMappingTransformerExtension\"\n```\n\nProgrammatically in Java:\n```java\nnew WireMockServer(\n    wireMockConfig().extensions(\n        \"com.github.masonm.wiremock.extension.JsExtendApiExtension\",\n        \"com.github.masonm.wiremock.extension.CompositeRequestMatcherExtension\",\n        \"com.github.masonm.wiremock.extension.CompositeResponseDefinitionTransformer\",\n        \"com.github.masonm.wiremock.extension.CompositeResponseTransformer\",\n        \"com.github.masonm.wiremock.extension.CompositeStubMappingTransformer\"\n    )\n)\n```\n\n# Usage\n\n## API Endpoints\n\nThe extension adds the following admin API endpoints. The URL parameter `{type}` should be one of `response-transformer`, `response-definition-transformer`, `request-matcher`, or `stub-mapping-transformer`.\n* `PUT /__admin/extensions/{type}/{name}` - Create new extension with type `{type}` and name `{name}`. The request body should be the Javascript source for the transformer or matcher function.\n* `GET /__admin/extensions/{type}/{name}` - Retrieves extension of type `{type}` and name `{name}`.\n* `DELETE /__admin/extensions/{id}/{name}` - Deletes extension of type `{type}` and name `{name}`.\n* `GET /__admin/extensions/{type}` - Returns array of all registered extensions of type `{type}`.\n* `DELETE /__admin/extensions/{type}` - Deletes all registered extensions of the type `{type}`.\n\n## Javascript API\n\nExtensions must consist of a single Javascript function with a prototype matching the corresponding Java class:\n* [ResponseTransformer](https://github.com/tomakehurst/wiremock/blob/7610d003720e1b39c994f95dcd36b3e3e48b9b9b/src/main/java/com/github/tomakehurst/wiremock/extension/ResponseTransformer.java#L25). Example:\n    ```javascript\n    function transform(request, response, files, parameters) {\n        return Response.Builder.like(response).but().body(\"TRANSFORMED!\").build();\n    }\n    ```\n* [ResponseDefinitionTransformer](https://github.com/tomakehurst/wiremock/blob/7610d003720e1b39c994f95dcd36b3e3e48b9b9b/src/main/java/com/github/tomakehurst/wiremock/extension/ResponseTransformer.java#L25). Example:\n    ```javascript\n    function transform(request, responseDefinition, files, parameters) {\n        return new ResponseDefinition(201, \"TRANSFORMED!\");\n    }\n    ```\n* [RequestMatcherExtension](https://github.com/tomakehurst/wiremock/blob/7610d003720e1b39c994f95dcd36b3e3e48b9b9b/src/main/java/com/github/tomakehurst/wiremock/matching/RequestMatcherExtension.java#L32). Example:\n    ```javascript\n    function match(request, parameters) {\n        var queryParam = parameters.getString(\"queryParam\");\n        return MatchResult.of(request.queryParameter(queryParam).isPresent());\n    }\n    ```\n    \n* [StubMappingTransformer](https://github.com/tomakehurst/wiremock/blob/7610d003720e1b39c994f95dcd36b3e3e48b9b9b/src/main/java/com/github/tomakehurst/wiremock/extension/StubMappingTransformer.java#L26). Example:\n    ```javascript\n    function transform(stubMapping) {\n        var newRequest = RequestPatternUpdater\n            .like(stubMapping.getRequest())\n            .withUrl(\"http://example.com\")\n            .build();\n        stubMapping.setRequest(newRequest);\n        return stubMapping;\n    }\n    ```\n\nIf you're using Java 8, then [many classes are already imported for you](https://github.com/MasonM/wiremock-jsextend/blob/master/src/main/java/com/github/masonm/wiremock/model/JsExtensionFactory.java#L53) are already imported for you. To import other classes, [use the Java.type() extension](http://www.n-k.de/riding-the-nashorn/#_invoking_java_methods_from_javascript).\n\n## Request Matching\n\nDue to Wiremock limitations, it's not possible to specify the name for a new request matcher. To use a request matcher, pass `\"composite-request-matcher-extension\"` as the name, along with any parameters you want to use. This will cause `wiremock-jsextend` to match the request against every matcher you've registered, in the order they were registered. The results are  aggregated using `MatchResult.aggregate()` and returned. You can use a parameter to ensure only one of your matchers if used, e.g.:\n```sh\n# Define request matcher that returns MatchResult.exactMatch() unless the parameter \"urlHasFoo\" is present\n$ curl -s -d '{\n    function match(request, parameters) {\n        if (!parameters || !parameters.containsKey(\"urlHasFoo\")) {\n            return MatchResult.exactMatch();\n        }\n        return MatchResult.of(request.getUrl().indexOf(\"foo\") != -1);\n    }\n' http://localhost:8080/__admin/extensions/RequestMatcherExtension/hasFoo \u003e /dev/null\n\n# Define test stub mapping that passes the \"urlHasFoo\" parameter\n$ curl -s -d '{\n    \"request\": {\n        \"customMatcher\": {\n            \"name\": \"composite-request-matcher-extension\",\n            \"parameters\": {\n                \"urlHasFoo\": true\n            }\n        }\n    },\n    \"response\": { \"body\": \"MATCHED!\" }\n}' http://localhost:8080/__admin/mappings \u003e /dev/null\n\n# Test it!\n$ curl -s http://localhost:8080/foo\nMATCHED!\n\n$ curl -I -s http://localhost:8080/bar\nHTTP/1.1 404 Not Found\nCache-Control: must-revalidate,no-cache,no-store\nContent-Type: text/html; charset=ISO-8859-1\nContent-Length: 286\nServer: Jetty(9.2.13.v20150730)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmasonm%2Fwiremock-jsextend","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmasonm%2Fwiremock-jsextend","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmasonm%2Fwiremock-jsextend/lists"}