{"id":18875824,"url":"https://github.com/wiremock/grpc-wiremock","last_synced_at":"2025-04-14T17:31:40.681Z","repository":{"id":189534696,"uuid":"642235444","full_name":"wiremock/grpc-wiremock","owner":"wiremock","description":"gRPC Mock Server","archived":false,"fork":false,"pushed_at":"2023-10-09T14:35:32.000Z","size":294,"stargazers_count":4,"open_issues_count":2,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-04-16T04:10:16.101Z","etag":null,"topics":["hacktoberfest"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"Adven27/grpc-wiremock","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wiremock.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}},"created_at":"2023-05-18T05:49:00.000Z","updated_at":"2023-08-30T08:53:55.000Z","dependencies_parsed_at":null,"dependency_job_id":"997fed0c-b433-4cd9-a588-9d14198e13db","html_url":"https://github.com/wiremock/grpc-wiremock","commit_stats":null,"previous_names":["wiremock/grpc-wiremock"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wiremock%2Fgrpc-wiremock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wiremock%2Fgrpc-wiremock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wiremock%2Fgrpc-wiremock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wiremock%2Fgrpc-wiremock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wiremock","download_url":"https://codeload.github.com/wiremock/grpc-wiremock/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223639348,"owners_count":17177816,"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","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":["hacktoberfest"],"created_at":"2024-11-08T06:09:17.570Z","updated_at":"2024-11-08T06:09:18.270Z","avatar_url":"https://github.com/wiremock.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WireMock Adapter for gRPC\n\n[![Stability: Experimental](https://masterminds.github.io/stability/experimental.svg)](https://masterminds.github.io/stability/experimental.html)\n\n\u003e **WARNING:** There is a new official [gRPC extension for WireMock](https://github.com/wiremock/wiremock-grpc-extension) under active development.\n\u003e The extension allows implementing proper matching and gRPC-specific functionality, instead of just using a converter bridge.\n\u003e We are looking for feedback and contributions!\n\u003e See [wiremock/wiremock #2148](https://github.com/wiremock/wiremock/issues/2148) for the feature request about providing an officially supported implementation.\n\u003e \n\u003e **CREDITS:** This repository was forked from [Adven27/grpc-wiremock](https://github.com/Adven27/grpc-wiremock) which was archived by the maintainer.\n\u003e This fork is used to preserve the repository, and to make it available for experimental use.\n\n_grpc-wiremock_ is a **mock server** for **GRPC** services implemented as a wrapper around the [WireMock](https://wiremock.org) HTTP server.\nIt is implementated in Java and runs as a standalone proxy container.\n\n## How It Works\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"doc/overview.drawio.svg\"/\u003e\n\u003c/p\u003e\n\n*grpc-wiremock* starts a gRPC server generated based on provided proto files which will convert a proto grpc request to JSON and redirects it as a POST request to the WireMock then converts a http response back to grpc proto format.\n1. GRPC server works on `tcp://localhost:50000`\n2. WireMock server works on `http://localhost:8888`\n\n## Quick Start\n\n### Run\n\n```posh\ndocker run -p 8888:8888 -p 50000:50000 -v $(pwd)/example/proto:/proto -v $(pwd)/example/wiremock:/wiremock wiremock/grpc-wiremock\n```\n\n### Stub\n\n```posh\ncurl -X POST http://localhost:8888/__admin/mappings \\\n  -d '{\n    \"request\": {\n        \"method\": \"POST\",\n        \"url\": \"/BalanceService/getUserBalance\",\n        \"headers\": {\"withAmount\": {\"matches\": \"\\\\d+\\\\.?\\\\d*\"} },\n        \"bodyPatterns\" : [ {\n            \"equalToJson\" : { \"userId\": \"1\", \"currency\": \"EUR\" }\n        } ]\n    },\n    \"response\": {\n        \"status\": 200,\n        \"jsonBody\": { \n            \"balance\": { \n                \"amount\": { \"value\": { \"decimal\" : \"{{request.headers.withAmount}}\" }, \"value_present\": true },\n                \"currency\": { \"value\": \"EUR\", \"value_present\": true }\n            } \n        }\n    }\n}'\n```\n\n### Check\n\n```posh\ngrpcurl -H 'withAmount: 100.0' -plaintext -d '{\"user_id\": 1, \"currency\": \"EUR\"}' localhost:50000 api.wallet.BalanceService/getUserBalance\n```\n\nShould get response:\n\n```json\n{\n  \"balance\": {\n    \"amount\": {\n      \"value\": {\n        \"decimal\": \"100.0\"\n      },\n      \"value_present\": true\n    },\n    \"currency\": {\n      \"value\": \"EUR\",\n      \"value_present\": true\n    }\n  }\n}\n```\n\n## Stubbing\n\nStubbing should be done via [WireMock JSON API](http://wiremock.org/docs/stubbing/)\n\n### Error mapping\n\nDefault error (not `200 OK`) mapping is based on https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto :\n\n| HTTP Status Code          | GRPC Status        | \n|---------------------------|:-------------------|\n| 400 Bad Request           | INVALID_ARGUMENT   |\n| 401 Unauthorized          | UNAUTHENTICATED    |\n| 403 Forbidden             | PERMISSION_DENIED  |\n| 404 Not Found             | NOT_FOUND          |\n| 409 Conflict              | ALREADY_EXISTS     |\n| 429 Too Many Requests     | RESOURCE_EXHAUSTED |\n| 499 Client Closed Request | CANCELLED          |\n| 500 Internal Server Error | INTERNAL           |\n| 501 Not Implemented       | UNIMPLEMENTED      |\n| 503 Service Unavailable   | UNAVAILABLE        |\n| 504 Gateway Timeout       | DEADLINE_EXCEEDED  |\n\nAnd could be overridden or augmented by overriding or augmenting the following properties:\n\n```yaml\ngrpc:\n  error-code-by:\n    http:\n      status-code:\n        400: INVALID_ARGUMENT\n        401: UNAUTHENTICATED\n        403: PERMISSION_DENIED\n        404: NOT_FOUND\n        409: ALREADY_EXISTS\n        429: RESOURCE_EXHAUSTED\n        499: CANCELLED\n        500: INTERNAL\n        501: UNIMPLEMENTED\n        503: UNAVAILABLE\n        504: DEADLINE_EXCEEDED\n```\n\nFor example:\n\n```posh\ndocker run \\\n    -e GRPC_ERRORCODEBY_HTTP_STATUSCODE_400=OUT_OF_RANGE \\\n    -e GRPC_ERRORCODEBY_HTTP_STATUSCODE_510=DATA_LOSS \\\n    wiremock/grpc-wiremock\n```\n\n## How To\n\n### 1. Configure gRPC server\n\nCurrently, following grpc server properties are supported:\n\n```properties\nGRPC_SERVER_PORT\nGRPC_SERVER_MAXHEADERLISTSIZE\nGRPC_SERVER_MAXMESSAGESIZE\nGRPC_SERVER_MAXINBOUNDMETADATASIZE\nGRPC_SERVER_MAXINBOUNDMESSAGESIZE\n```\n\nCould be used like this:\n\n```posh\ndocker run -e GRPC_SERVER_MAXHEADERLISTSIZE=1000 wiremock/grpc-wiremock\n```\n\n### 2. Configure WireMock server\n\nWireMock server may be configured by passing [command line options](http://wiremock.org/docs/running-standalone/) \nprefixed by `wiremock_`:\n\n```posh\ndocker run -e WIREMOCK_DISABLE-REQUEST-LOGGING -e WIREMOCK_PORT=0 wiremock/grpc-wiremock\n```\n\n### 3. Mock server-side streaming\n\nGiven the service:\n\n```protobuf\nservice WalletService {\n  rpc searchTransaction (SearchTransactionRequest) returns (stream SearchTransactionResponse) {}\n}\n```\n\nThen the following stub may be provided, where `response.headers.streamSize` specifies\nhow many responses should be returned during the stream (`1` - if absent).\n\nThe current response iteration number is available in `request.headers.streamCursor`:\n\n```posh\ncurl -X POST http://localhost:8888/__admin/mappings \\\n  -d '{\n  \"request\": {\n    \"method\": \"POST\",\n    \"url\": \"/WalletService/searchTransaction\"\n  },\n  \"response\": {\n    \"fixedDelayMilliseconds\": 1000,\n    \"headers\": {\"streamSize\": \"5\" },\n    \"jsonBody\": {\n      \"transactions\": [\n        {\n          \"id\": \"{{request.headers.streamCursor}}\",\n          \"userId\": \"1\",\n          \"currency\": \"EUR\",\n          \"amount\": {\n            \"decimal\": \"{{request.headers.streamCursor}}00\"\n          }\n        },\n        {\n          \"id\": \"100{{request.headers.streamCursor}}\",\n          \"userId\": \"2\",\n          \"currency\": \"EUR\",\n          \"amount\": {\n            \"decimal\": \"200\"\n          }\n        }\n      ]\n    }\n  }\n}'\n```\n\n### 4. Speed up container start\n\nIn case you don't need to change proto files, you can build your own image with precompiled protos.  \nSee an [example](/example/Dockerfile)\n\n### 5. Use with snappy compresser/decompresser\n\nSnappy support can be enabled using `EXTERNAL_CODECS` env variable as follows:\n\n```posh\ndocker run -e EXTERNAL_CODECS=\"snappy, another\" wiremock/grpc-wiremock\n```\n\nAlso in docker-compose:\n\n```posh\n    image: wiremock/grpc-wiremock\n    ports:\n      - \"12085:50000\" # grpc port\n      - \"8088:8888\" # http serve port\n    volumes:\n      - ./example/proto:/proto\n    environment:\n      - EXTERNAL_CODECS=snappy\n```\n\n\u003csub\u003e*gzip compression supported by default\u003c/sub\u003e\n\n### 6. Use in load testing\n\nTo increase performance some Wiremock related options may be tuned either directly or by enabling the \"load\" profile.\nNext two commands are identical:\n\n```posh\ndocker run -e SPRING_PROFILES_ACTIVE=load wiremock/grpc-wiremock\n```\n\n```posh\ndocker run \\\n  -e WIREMOCK_NO-REQUEST-JOURNAL \\\n  -e WIREMOCK_DISABLE-REQUEST-LOGGING \\\n  -e WIREMOCK_ASYNC-RESPONSE-ENABLED \\\n  -e WIREMOCK_ASYNC-RESPONSE-THREADS=10 \\\n  wiremock/grpc-wiremock\n```\n\n### 7. Preserving proto field names in stubs\n\nBy default, stub mappings must have proto fields references in lowerCamlCase, e.g. proto field `user_id` must be referenced as:\n\n```json\n{\n  \"request\": {\n    \"method\": \"POST\",\n    \"url\": \"/BalanceService/getUserBalance\",\n    \"bodyPatterns\": [{\"equalToJson\": { \"userId\": \"1\" }}]\n  }\n}\n```\n\nTo preserve proto field names the following env variable could be used:\n\n```posh\ndocker run -e JSON_PRESERVING_PROTO_FIELD_NAMES=true wiremock/grpc-wiremock\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwiremock%2Fgrpc-wiremock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwiremock%2Fgrpc-wiremock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwiremock%2Fgrpc-wiremock/lists"}