diff --git a/docs/_sidebar.md b/docs/_sidebar.md index 5dbb220c..13378217 100644 --- a/docs/_sidebar.md +++ b/docs/_sidebar.md @@ -13,6 +13,7 @@ - Rest API - [List stubs](api-stubs-list) + - [List unused stubs](api-unused-stubs-list) - [Add stub](api-stubs-add) - [Delete stub](api-stubs-delete) - [Search stub](api-stubs-search) diff --git a/docs/api-stubs-delete.md b/docs/api-stubs-delete.md index 7f4ab802..2f82b1ac 100644 --- a/docs/api-stubs-delete.md +++ b/docs/api-stubs-delete.md @@ -1,3 +1,12 @@ ## Rest API. Stubs Delete -!> The delete functionality is under development. It is planned to be implemented in the near future. +Stubs Delete — endpoint removes stub by ID. + +Enough to knock on the handle `DELETE /api/stubs/{uuid}`: +```bash +curl -X DELETE http://127.0.0.1:4771/api/stubs/6c85b0fa-caaf-4640-a672-f56b7dd8074d +``` + +The endpoint will respond with code 204, the stub has been removed. + +It worked! diff --git a/docs/api-stubs-search.md b/docs/api-stubs-search.md index b0f6e870..e666faab 100644 --- a/docs/api-stubs-search.md +++ b/docs/api-stubs-search.md @@ -37,7 +37,36 @@ Enough to knock on the handle POST /api/stubs/search: Response: ```json -["6c85b0fa-caaf-4640-a672-f56b7dd8074d"] +{ + "data":{ + "message": "World", + "return_code": 0 + }, + "error": "" +} +``` + +## Find by ID + +Enough to knock on the handle `POST /api/stubs/search`: +```bash +curl -X POST -d '{ \ + "id": "6c85b0fa-caaf-4640-a672-f56b7dd8074d", \ + "service": "Gripmock", \ + "method": "SayHello", \ + "data":{} \ +}' http://127.0.0.1:4771/api/stubs/search +``` + +Response: +```json +{ + "data":{ + "message": "World", + "return_code": 0 + }, + "error": "" +} ``` ## Input Matching diff --git a/docs/api-unused-stubs-list.md b/docs/api-unused-stubs-list.md new file mode 100644 index 00000000..720afc7e --- /dev/null +++ b/docs/api-unused-stubs-list.md @@ -0,0 +1,77 @@ +## Rest API. Stubs Unused List + +Stubs Unused List — endpoint returns a list of unused stubs (all stubs that were not accessed through search). +A very useful method that helps find dead stubs in the code. + +Let's imagine that our contract `simple.proto` looks something like this: +```protobuf +syntax = "proto3"; +option go_package = "github.com/bavix/gripmock/protogen/example/simple"; + +package simple; + +service Gripmock { + rpc SayHello (Request) returns (Reply); +} + +message Request { + string name = 1; +} + +message Reply { + string message = 1; + int32 return_code = 2; +} +``` + +Enough to knock on the handle `GET /api/stubs/unused`: +```bash +curl http://127.0.0.1:4771/api/stubs/unused +``` + +Response: +```json +[ + { + "id": "6c85b0fa-caaf-4640-a672-f56b7dd8074d", + "service": "Gripmock", + "method": "SayHello", + "input": { + "equals": { + "name": "gripmock" + }, + "contains": null, + "matches": null + }, + "output": { + "data": { + "message": "Hello GripMock", + "return_code": 42 + }, + "error": "" + } + } +] +``` + +Find stub by ID. Enough to knock on the handle `POST /api/stubs/search`: +```bash +curl -X POST -d '{ \ + "id": "6c85b0fa-caaf-4640-a672-f56b7dd8074d", \ + "service": "Gripmock", \ + "method": "SayHello", \ + "data":{} \ +}' http://127.0.0.1:4771/api/stubs/search +``` + +Now the stub is marked as used. Let's try to get a list of unused stubs. +```bash +curl http://127.0.0.1:4771/api/stubs/unused +``` + +Response: +```json +[] +``` + +It worked! \ No newline at end of file diff --git a/docs/static-stubs-benefits-yaml.md b/docs/static-stubs-benefits-yaml.md index d347bd93..ece4e51d 100644 --- a/docs/static-stubs-benefits-yaml.md +++ b/docs/static-stubs-benefits-yaml.md @@ -77,7 +77,7 @@ You can read more details here: https://github.com/goccy/go-yaml#2-reference-ele input: equals: name: tokopedia - traceID: &traceID 0ad1348f1403169275002100356696 + code: &code 0ad1348f1403169275002100356696 output: data: &result message: Hello Tokopedia @@ -87,7 +87,7 @@ You can read more details here: https://github.com/goccy/go-yaml#2-reference-ele input: equals: name: world - traceID: *traceID + code: *code output: data: *result ```