### Execute Go gRPC Client Example Source: https://github.com/tokopedia/gripmock/blob/master/Readme.md This command runs the provided Go client example, which is designed to interact with the running GripMock server. It demonstrates how a gRPC client can make calls to the mocked service. ```Go go run example/simple/client/*.go ``` -------------------------------- ### Example Gripmock Stub for Greeter SayHello Service Source: https://github.com/tokopedia/gripmock/blob/master/Readme.md An example of a Gripmock stub definition for the 'Greeter' service's 'SayHello' method, demonstrating an 'equals' input match for the name 'gripmock' and a corresponding output message. ```JSON { "service":"Greeter", "method":"SayHello", "input":{ "equals":{ "name":"gripmock" } }, "output":{ "data":{ "message":"Hello GripMock" } } } ``` -------------------------------- ### Gripmock Input Headers Matching Rule Example Source: https://github.com/tokopedia/gripmock/blob/master/Readme.md An example demonstrating how to specify header matching rules within the 'input' object of a stub definition. Headers are treated as a map of strings, and the same matching rules (equals, equals_unordered, contains, matches) apply, with only the first specified rule being applied. ```JSON { "service": "YourService", "method": "YourMethod", "input": { "equals": { "field1": "value1" }, "headers": { "equals": { "Content-Type": "application/json" } // Only one rule type is applied. If you specify multiple rules, // the first matching rule will be used. } }, "output": { "data": { "result": "success" } } } ``` -------------------------------- ### Run GripMock Docker Container Source: https://github.com/tokopedia/gripmock/blob/master/Readme.md This command starts the GripMock server within a Docker container. It mounts a local directory containing the .proto file into the container and exposes the gRPC (4770) and HTTP stub (4771) ports for client and stub management interactions. ```Shell docker run -p 4770:4770 -p 4771:4771 -v /mypath:/proto tkpd/gripmock /proto/hello.proto ``` -------------------------------- ### Example Curl Request to Gripmock Find Endpoint Source: https://github.com/tokopedia/gripmock/blob/master/Readme.md A curl command demonstrating how to send a POST request to the `/find` endpoint with a JSON payload to search for a matching stub. ```bash curl -X POST -d '{"service":"Greeter","method":"SayHello","data":{"name":"gripmock"}}' localhost:4771/find ``` -------------------------------- ### Gripmock Static Stubbing with Docker Mounts Source: https://github.com/tokopedia/gripmock/blob/master/Readme.md Command to run Gripmock with static stub files mounted from a local path, demonstrating how to provide a stub file path using the `--stub` argument and mount proto files. ```docker docker run -p 4770:4770 -p 4771:4771 -v /mypath:/proto -v /mystubs:/stub tkpd/gripmock --stub=/stub /proto/hello.proto ``` -------------------------------- ### Pull GripMock Docker Image Source: https://github.com/tokopedia/gripmock/blob/master/Readme.md This command pulls the official GripMock Docker image from the registry, making it available locally for use. ```Shell docker pull tkpd/gripmock ``` -------------------------------- ### Add Stub Mapping to GripMock Server Source: https://github.com/tokopedia/gripmock/blob/master/Readme.md This cURL command adds a new stub mapping to the GripMock stub service via its HTTP API. It specifies the gRPC service and method, defines an input expectation (name equals 'gripmock'), and sets the desired output response ('Hello GripMock'). ```Shell curl -X POST -d '{"service":"Gripmock","method":"SayHello","input":{"equals":{"name":"gripmock"}},"output":{"data":{"message":"Hello GripMock"}}}' localhost:4771/add ``` -------------------------------- ### Gripmock Dynamic Stubbing REST API Reference Source: https://github.com/tokopedia/gripmock/blob/master/Readme.md Gripmock's HTTP stub server provides a REST API on port `:4771` for dynamic management of stub mappings and recorded requests. ```APIDOC HTTP Stub Server: :4771 GET / Description: Lists all currently active stub mappings. Returns: JSON array of stub mappings. POST /add Description: Adds a new stub mapping. Parameters: body: JSON object (Stub Format) - The stub data to add. Returns: Success/Error message. POST /find Description: Finds a matching stub based on provided input data. Parameters: body: JSON object (Input Matching Find Format) - The input data to match against stored stubs. Returns: Matching stub data or null if no match. GET /clear Description: Clears all existing stub mappings. Returns: Success message. POST /reset Description: Resets stub mappings by clearing all current stubs and reloading them from the configured stub file path (if provided during Gripmock startup). Returns: Success message. GET /requests Description: Lists all recorded requests that have been made to the stub server. Returns: JSON array of recorded requests. ``` -------------------------------- ### Gripmock Input Matching Rule: Matches (Regex) Source: https://github.com/tokopedia/gripmock/blob/master/Readme.md The 'matches' rule uses regular expressions to match field values in the input, providing flexible pattern-based matching for strings and array elements. ```JSON { . . "input":{ "matches":{ "name":"^grip.*$", "cities": ["Jakarta", "Istanbul", ".*grad$"] } } . . } ``` -------------------------------- ### Gripmock Stub JSON Format Schema Source: https://github.com/tokopedia/gripmock/blob/master/Readme.md The standard JSON format for defining a Gripmock stub, specifying the service, method, input matching rules, and expected output data, headers, error messages, and gRPC response codes. ```JSON { "service":"", // name of service defined in proto "method":"", // name of method that we want to mock "input":{ // input matching rule. see Input Matching Rule section below // put rule here }, "output":{ // output json if input were matched "data":{ // put result fields here }, "headers": { // put result headers here }, "error":"" // Optional. if you want to return error instead. "code":"" // Optional. Grpc response code. if code !=0 return error instead. } } ``` -------------------------------- ### Gripmock Input Matching Find Endpoint Request Format Source: https://github.com/tokopedia/gripmock/blob/master/Readme.md The JSON format for the request body sent to the `/find` endpoint to locate a matching stub based on service, method, and input data. ```JSON { "service":"", "method":"", "data":{ // input that is supposed to match with stored stubs } } ``` -------------------------------- ### Gripmock Input Matching Rule: Equals Source: https://github.com/tokopedia/gripmock/blob/master/Readme.md The 'equals' rule matches the exact field name and value of the input against the expected stub. It supports nested fields and various JSON data types including strings, booleans, arrays, and null. ```JSON { . . "input":{ "equals":{ "name":"gripmock", "greetings": { "english": "Hello World!", "indonesian": "Halo Dunia!", "turkish": "Merhaba Dünya!" }, "ok": true, "numbers": [4, 8, 15, 16, 23, 42], "null": null } } . . } ``` -------------------------------- ### Gripmock Input Matching Rule: Equals Unordered Source: https://github.com/tokopedia/gripmock/blob/master/Readme.md The 'equals_unordered' rule matches the exact field name and value, similar to 'equals', but treats lists as sets, meaning the order of elements in arrays does not matter for a match. ```JSON { . . "input":{ "equals_unordered":{ "name":"gripmock", "greetings": { "english": "Hello World!", "indonesian": "Halo Dunia!", "turkish": "Merhaba Dünya!" }, "ok": true, "numbers": [4, 8, 15, 16, 23, 42], "null": null } } . . } ``` -------------------------------- ### Gripmock Input Matching Rule: Contains Source: https://github.com/tokopedia/gripmock/blob/master/Readme.md The 'contains' rule matches if the input includes the specified fields and their values, allowing for partial matches within the input data. ```JSON { . . "input":{ "contains":{ "field2":"hello", "field4":{ "field5": "value5" } } } . . } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.