{"id":23035812,"url":"https://github.com/lucasls/wiremock-kotlin-extensions","last_synced_at":"2025-10-27T04:14:33.843Z","repository":{"id":37259871,"uuid":"274213440","full_name":"lucasls/wiremock-kotlin-extensions","owner":"lucasls","description":"WireMock is awesome, Java DSLs not that much. This is a Kotlin DSL for WireMock built on extension functions","archived":false,"fork":false,"pushed_at":"2022-06-20T22:45:56.000Z","size":126,"stargazers_count":2,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-06T15:51:25.569Z","etag":null,"topics":["dsl","kotlin","wiremock"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lucasls.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}},"created_at":"2020-06-22T18:28:08.000Z","updated_at":"2023-08-31T16:07:38.000Z","dependencies_parsed_at":"2022-09-26T21:41:24.830Z","dependency_job_id":null,"html_url":"https://github.com/lucasls/wiremock-kotlin-extensions","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/lucasls/wiremock-kotlin-extensions","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucasls%2Fwiremock-kotlin-extensions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucasls%2Fwiremock-kotlin-extensions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucasls%2Fwiremock-kotlin-extensions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucasls%2Fwiremock-kotlin-extensions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lucasls","download_url":"https://codeload.github.com/lucasls/wiremock-kotlin-extensions/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucasls%2Fwiremock-kotlin-extensions/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281212176,"owners_count":26462252,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-27T02:00:05.855Z","response_time":61,"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":["dsl","kotlin","wiremock"],"created_at":"2024-12-15T16:47:05.769Z","updated_at":"2025-10-27T04:14:33.810Z","avatar_url":"https://github.com/lucasls.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"[ ![JCenter](https://api.bintray.com/packages/lucasls/oss/wiremock-kotlin-extensions/images/download.svg) ](https://bintray.com/lucasls/oss/wiremock-kotlin-extensions/_latestVersion)\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.lucasls.kotlinx.wiremock/wiremock-kotlin-extensions/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.lucasls.kotlinx.wiremock/wiremock-kotlin-extensions)\n\n# WireMock Kotlin Extensions\n[WireMock](http://wiremock.org/) is awesome, using Java DSLs on Kotlin not that much. This lib aims to help with that. Making use of Kotlin's powerful Extension Functions, this lib enhances WireMock API without losing any existing functionality.\n\n# Getting Started\n\nWireMock Kotlin Extensions is published to Maven Central and JCenter.\n\n## Gradle\n```groovy\ntestCompile \"com.github.lucasls.kotlinx.wiremock:wiremock-kotlin-extensions:0.1.2\"\ntestCompile \"com.github.tomakehurst:wiremock-jre8:2.27.2\"\n```\n\n## Maven\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.github.lucasls.kotlinx.wiremock\u003c/groupId\u003e\n    \u003cartifactId\u003ewiremock-kotlin-extensions\u003c/artifactId\u003e\n    \u003cversion\u003e0.10.0\u003c/version\u003e\n    \u003cscope\u003etest\u003c/scope\u003e\n\u003c/dependency\u003e\n\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.github.tomakehurst\u003c/groupId\u003e\n    \u003cartifactId\u003ewiremock-jre8\u003c/artifactId\u003e\n    \u003cversion\u003e2.27.2\u003c/version\u003e\n    \u003cscope\u003etest\u003c/scope\u003e\n\u003c/dependency\u003e\n```\n\n\n## Stubbing\n\n```kotlin\nstubFor(\n    get(urlEqualTo(\"/my/resource\")) {\n        withHeader(\"Accept\", equalTo(\"text/xml\"))\n\n        willReturnAResponse {\n            withStatus(200)\n            withHeader(\"Content-Type\", \"text/xml\")\n            withBody(\"\u003cresponse\u003eSome content\u003c/response\u003e\")\n        }\n    },\n\n    post(urlEqualTo(\"/my/resource\")) {\n        withHeader(\"Accept\", equalTo(\"text/xml\"))\n\n        willReturnAResponse {\n            withStatus(200)\n            withHeader(\"Content-Type\", \"text/xml\")\n            withBody(\"\u003cresponse\u003eSome content\u003c/response\u003e\")\n        }\n    }\n)\n```\n\n## Verifying\n\n```kotlin\nverify {\n    n * postRequestedFor(urlMatching(\"/my/resource/[a-z0-9]+\")) {\n        withRequestBody(matching(\".*\u003cmessage\u003e1234\u003c/message\u003e.*\"))\n        withHeader(\"Content-Type\", notMatching(\"application/json\"))\n    }\n\n    1 * getRequestedFor(urlMatching(\"/my/resource/[a-z0-9]+\")) {\n        withRequestBody(matching(\".*\u003cmessage\u003e1234\u003c/message\u003e.*\"))\n        withHeader(\"Content-Type\", notMatching(\"application/json\"))\n    }\n}\n```\n\n## Experimental Stubbing DSL\n\n```kotlin\nstubFor {\n    (\"GET\" to \"/my/resource\") {\n        withHeader(\"Accept\", equalTo(\"text/xml\"))\n\n        willReturnAResponse {\n            withStatus(200)\n            withHeader(\"Content-Type\", \"text/xml\")\n            withBody(\"\u003cresponse\u003eSome content\u003c/response\u003e\")\n        }\n    }\n    \n    (\"POST\" to \"/my/resource\") {\n        withHeader(\"Accept\", equalTo(\"text/xml\"))\n\n        willReturnAResponse {\n            withStatus(200)\n            withHeader(\"Content-Type\", \"text/xml\")\n            withBody(\"\u003cresponse\u003eSome content\u003c/response\u003e\")\n        }\n    }\n}\n```\n\nWireMock reference: http://wiremock.org/docs/getting-started/\n\n\n# WireMock Standalone, Java 7, Java 8, ...\n\nThe WireMock Kotlin Extension dependency can be used alongside all different flavours of WireMock, namely:\n\n- **Java 7:** `com.github.tomakehurst:wiremock:2.x.x`\n- **Java 7 Standalone:** `com.github.tomakehurst:wiremock-standalone:2.x.x`\n- **Java 8:** `com.github.tomakehurst:wiremock-jre8:2.x.x`\n- **Java 8 Standalone:** `com.github.tomakehurst:wiremock-jre8-standalone:2.x.x`\n\nWireMock won't be automatically included as a transitive dependency, so please make sure to include it.  \n\nWireMock reference: http://wiremock.org/docs/download-and-installation/\n\n\n# How does it compare\n\nWireMock is perfectly functional with Kotlin, but feels dated, because Java was not built for DSLs.\n\nHere are some examples adapted from WireMock docs, comparing usages with both DSLs.\n\n## Stubbing\n\n**Original WireMock Java DSL**\n\n```kotlin\nstubFor(\n    get(urlEqualTo(\"/some/thing\"))\n        .willReturn(\n            aResponse()\n                .withHeader(\"Content-Type\", \"text/plain\")\n                .withBody(\"Hello world!\")))\n\nstubFor(get(urlEqualTo(\"/body\"))\n    .willReturn(aResponse()\n        .withBody(\"Literal text to put in the body\")))\n\nstubFor(any(anyUrl())\n    .atPriority(10)\n    .willReturn(aResponse()\n        .withStatus(404)\n        .withBody(\"\"\"{\"status\":\"Error\",\"message\":\"Endpoint not found\"}\"\"\")))\n\nstubFor(get(urlMatching(\"/api/.*\")).atPriority(5)\n    .willReturn(aResponse().withStatus(401)))\n\nstubFor(get(urlEqualTo(\"/todo/items\")).inScenario(\"To do list\")\n    .whenScenarioStateIs(STARTED)\n    .willReturn(aResponse()\n        .withBody(\"\"\"\u003citems\u003e\u003citem\u003eBuy milk\u003c/item\u003e\u003c/items\u003e\"\"\")))\n``` \n\n**WireMock Kotlin Extensions (Stable)**\n\n```kotlin\nstubFor(\n    get(urlEqualTo(\"/some/thing\")) {\n        willReturnAResponse {\n            withHeader(\"Content-Type\", \"text/plain\")\n            withBody(\"Hello world!\")\n        }\n    },\n\n    get(urlEqualTo(\"/body\")) {\n        willReturnAResponse {\n            withBody(\"Literal text to put in the body\")\n        }\n    },\n\n     any(anyUrl) {\n        atPriority(10)\n        willReturnAResponse {\n            withStatus(404)\n            withBody(\"\"\"{\"status\":\"Error\",\"message\":\"Endpoint not found\"}\"\"\")\n        }\n    },\n\n    get(urlMatching(\"/api/.*\")) {\n        atPriority(5)\n        willReturnAResponse {\n            withStatus(401)\n        }\n    },\n\n    get(urlEqualTo(\"/todo/items\")) {\n        inScenario(\"To do list\") {\n            whenScenarioStateIs(STARTED)\n            willReturnAResponse {\n                withBody(\"\"\"\u003citems\u003e\u003citem\u003eBuy milk\u003c/item\u003e\u003c/items\u003e\"\"\")\n            }\n        }\n    }\n)\n```\n\n**WireMock Kotlin Extensions (Experimental)**\n\n```kotlin\nstubFor {\n    (\"GET\" to \"/some/thing\") {\n        willReturnAResponse {\n            withHeader(\"Content-Type\", \"text/plain\")\n            withBody(\"Hello world!\")\n        }\n    }\n\n    (\"GET\" to \"/body\") {\n        willReturnAResponse {\n            withBody(\"Literal text to put in the body\")\n        }\n    }\n\n    (\"ANY\" to anyUrl) {\n        atPriority(10)\n        willReturnAResponse {\n            withStatus(404)\n            withBody(\"\"\"{\"status\":\"Error\",\"message\":\"Endpoint not found\"}\"\"\")\n        }\n    }\n\n    (\"GET\" to urlMatching(\"/api/.*\")) {\n        atPriority(5)\n        willReturnAResponse {\n            withStatus(401)\n        }\n    }\n\n    (\"GET\" to \"/todo/items\") {\n        inScenario(\"To do list\") {\n            whenScenarioStateIs(STARTED)\n            willReturnAResponse {\n                withBody(\"\"\"\u003citems\u003e\u003citem\u003eBuy milk\u003c/item\u003e\u003c/items\u003e\"\"\")\n            }\n        }\n    }\n}\n```\n\nWireMock reference\n- http://wiremock.org/docs/stubbing/\n- http://wiremock.org/docs/stateful-behaviour/\n\n## Verifying\n\n**Original WireMock Java DSL**\n\n````kotlin\nverify(postRequestedFor(urlEqualTo(\"/verify/this\"))\n            .withHeader(\"Content-Type\", equalTo(\"text/xml\")))\n\nverify(3, postRequestedFor(urlEqualTo(\"/three/times\")))\n\nverify(lessThan(5), postRequestedFor(urlEqualTo(\"/many\")))\n\nverify(lessThanOrExactly(5), postRequestedFor(urlEqualTo(\"/many\")))\n\nverify(exactly(5), postRequestedFor(urlEqualTo(\"/many\")))\n\nverify(moreThanOrExactly(5), postRequestedFor(urlEqualTo(\"/many\")))\n\nverify(moreThan(5), postRequestedFor(urlEqualTo(\"/many\")))\n````\n\n\n**WireMock Kotlin Extensions**\n\n```kotlin\nverify {\n    n * postRequestedFor(urlEqualTo(\"/verify/this\")) {\n        withHeader(\"Content-Type\", equalTo(\"text/xml\"))\n    }\n    \n    3 * postRequestedFor(urlEqualTo(\"/three/times\"))\n    \n    lessThan(5) * postRequestedFor(urlEqualTo(\"/many\"))\n    \n    lessThanOrExactly(5) * postRequestedFor(urlEqualTo(\"/many\"))\n    \n    exactly(5) * postRequestedFor(urlEqualTo(\"/many\"))\n    \n    moreThanOrExactly(5) * postRequestedFor(urlEqualTo(\"/many\"))\n    \n    moreThan(5) * postRequestedFor(urlEqualTo(\"/many\"))\n}\n```\n\nWireMock reference: http://wiremock.org/docs/verifying/\n\n## Request Matching\n\n**Original WireMock Java DSL**\n\n```kotlin\nstubFor(any(urlPathEqualTo(\"/everything\"))\n    .withHeader(\"Accept\", containing(\"xml\"))\n    .withCookie(\"session\", matching(\".*12345.*\"))\n    .withQueryParam(\"search_term\", equalTo(\"WireMock\"))\n    .withBasicAuth(\"jeff@example.com\", \"jeffteenjefftyjeff\")\n    .withRequestBody(equalToXml(\"\u003csearch-results /\u003e\"))\n    .withRequestBody(matchingXPath(\"//search-results\"))\n    .withMultipartRequestBody(\n        aMultipart()\n            .withName(\"info\")\n            .withHeader(\"Content-Type\", containing(\"charset\"))\n            .withBody(equalToJson(\"{}\"))\n    )\n    .willReturn(aResponse()))\n``` \n\n**WireMock Kotlin Extensions**\n\n```kotlin\nstubFor(\n    any(urlPathEqualTo(\"/everything\")) {\n        withHeader(\"Accept\", containing(\"xml\"))\n        withCookie(\"session\", matching(\".*12345.*\"))\n        withQueryParam(\"search_term\", equalTo(\"WireMock\"))\n        withBasicAuth(\"jeff@example.com\", \"jeffteenjefftyjeff\")\n        withRequestBody(equalToXml(\"\u003csearch-results /\u003e\"))\n        withRequestBody(matchingXPath(\"//search-results\"))\n\n        withMultipartRequestBody {\n            withName(\"info\")\n            withHeader(\"Content-Type\", containing(\"charset\"))\n            withBody(equalToJson(\"{}\"))\n        }\n\n        willReturnAResponse()\n    }\n)\n```\n\nWireMock reference: http://wiremock.org/docs/request-matching/\n\n# Compatibility\n\nWireMock Kotlin Extensions is 100% compatible with the original WireMock API.\nIn fact, most of the time while using the DSL you'll be using WireMock directly.\n\nThat's because this project is powered by Kotlin's extension functions, and inspired\nby projects like [Mockito Kotlin](https://github.com/nhaarman/mockito-kotlin) and \n[Kotlin Logging](https://github.com/MicroUtils/kotlin-logging), which manage to enable\ndevelopers to write idiomatic Kotlin code without breaking compatibility with the \nexisting Java ecosystem.\n\nSome the advantages of this approach are:\n- There's virtually no limitation to using this library compared to using WireMock directly: any\nunimplemented functionality can be called using the existing Java API\n- Existing projects making use of WireMock can incrementally adopt this library, including\nprojects which mixed Java and Kotlin source codes\n- Existing WIreMock documentation, third party help articles, Stackoverflow questions still apply most \nof the time.\n\nOf course there are disadvantages, like losing null safety and being restricted to the JVM.\n\n# Contributing\n\nThis library is in very early stages, and there's a lot to improve.\nFeel free to contact me if you would like to contribute in any way.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucasls%2Fwiremock-kotlin-extensions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucasls%2Fwiremock-kotlin-extensions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucasls%2Fwiremock-kotlin-extensions/lists"}