Admin API Reference

Stef Heyenrath edited this page Aug 4, 2018 · 28 revisions

Admin API Reference

The WireMock admin API provides functionality to define the mappings via a http/https interface. To use this interface, you need to enable the admin interface in code:

var server = FluentMockServer.StartWithAdminInterface();

API definition

A Swagger 2.0 definition can be found on swagger hub.

Supported interfaces

The following interfaces are supported:

/__admin/settings

The global settings from the mock service.

  • GET /__admin/settings --> Gets the current global settings
  • POST /__admin/settings --> Updates the current global settings

/__admin/mappings

The mappings defined in the mock service.

  • GET /__admin/mappings --> Gets all defined mappings
  • POST /__admin/mappings --> Create a new stub mapping
  • DELETE /__admin/mappings or POST /__admin/mappings/reset --> Delete all stub mappings
  • GET /__admin/mappings/{guid} --> Get a single stub mapping
  • PUT /__admin/mappings/{guid} --> Update a stub mapping
  • DELETE /__admin/mappings/{guid} --> Delete a single stub mapping
  • POST /__admin/mappings/save --> Save all persistent stub mappings to the backing store

/__admin/requests

Logged requests and responses received by the mock service.

  • GET /__admin/requests --> Get received requests
  • DELETE /__admin/requests or POST /__admin/requests/reset --> Delete all received requests
  • GET /__admin/requests/{guid} --> Get a single request
  • POST /__admin/requests/count --> TODO
  • POST /__admin/requests/find --> Find requests
  • GET /__admin/requests/unmatched --> TODO
  • GET /__admin/requests/unmatched/near-misses --> TODO

For some example requests, see this PostMan Collection


/__admin/mappings

The mappings defined in the mock service.

GET /__admin/mappings

Gets all defined mappings.

Example request: GET http://localhost/__admin/mappings

Example response:

[
  {
    "Guid": "be6e1db8-cb95-4a15-a836-dcd0092b34a0",
    "Request": {
      "Path": {
        "Matchers": [
          {
            "Name": "WildcardMatcher",
            "Pattern": "/data"
          }
        ]
      },
      "Methods": [
        "get"
      ],
      "Headers": [
        {
          "Name": "Content-Type",
          "Matchers": [
            {
              "Name": "WildcardMatcher",
              "Pattern": "application/*"
            }
          ]
        }
      ],
      "Cookies": [],
      "Params": [
        {
          "Name": "start",
          "Values": [ "1000", "1001" ]
        }
      ],
      "Body": {}
    },
    "Response": {
      "StatusCode": 200,
      "Body": "{ \"result\": \"Contains x with FUNC 200\"}",
      "UseTransformer": false,
      "Headers": {
        "Content-Type": "application/json"
      }
    }
  },
  {
    "Guid": "90356dba-b36c-469a-a17e-669cd84f1f05",
    "Request": {
      "Path": {
        "Matchers": [
          {
            "Name": "WildcardMatcher",
            "Pattern": "/*"
          }
        ]
      },
      "Methods": [
        "get"
      ],
      "Headers": [],
      "Cookies": [],
      "Params": [
        {
          "Name": "start",
          "Values": []
        }
      ],
      "Body": {}
    },
    "Response": {
      "StatusCode": 200,
      "Body": "{\"msg\": \"Hello world, {{request.path}}\"",
      "UseTransformer": true,
      "Headers": {
        "Transformed-Postman-Token": "token is {{request.headers.Postman-Token}}",
        "Content-Type": "application/json"
      },
      "Delay": 10
    }
  }
]

POST /__admin/mappings

Create a new stub mapping

Example request:

{
    "Guid": "dae02a0d-8a33-46ed-aab0-afbecc8643e3",
    "Request": {
      "Url": "/testabc",
      "Methods": [
        "put"
      ],
      "Headers": [
        {
          "Name": "Content-Type",
          "Matchers": [
            {
              "Name": "WildcardMatcher",
              "Pattern": "application/*"
            }
          ]
        }
      ],
      "Cookies": [],
      "Params": [
        {
          "Name": "start",
          "Values": [ "1000", "1001" ]
        }
      ],
       "Body": {
        "Matcher": {
          "Name": "JsonPathMatcher",
          "Pattern": "$.things[?(@.name == 'RequiredThing')]"
        }
      }
    },
    "Response": {
      "UseTransformer": true,
      "StatusCode": 205,
      "BodyAsJson": { "result": "test - {{request.path}}" },
      "Headers": {
        "Content-Type": "application/json", "a" : "b"
      },
      "Delay": 10
    }
  }

Note : It's also possible to pre-load Mappings. This can be done by putting a file named {guid}.json in the __admin\mapping directory.

Example : 11111110-a633-40e8-a244-5cb80bc0ab66.json

{
    "Request": {
        "Path": {
            "Matchers": [
                {
                    "Name": "WildcardMatcher",
                    "Pattern": "/static/mapping"
                }
            ]
        },
        "Methods": [
            "get"
        ]
    },
    "Response": {
        "BodyAsJson": { "body": "static mapping" },
        "Headers": {
            "Content-Type": "application/json"
        }
    }
}

DELETE /__admin/mappings

Delete all stub mappings.

GET /__admin/mappings/{guid}

Get a single stub mapping

PUT /__admin/mappings/{guid}

Update a single stub mapping

Example request

{
  "Request": {
    "Path": {
      "Matchers": []
    },
    "Methods": [
      "get"
    ],
    "Headers": [],
    "Cookies": [],
    "Params": [
      {
        "Name": "start",
        "Values": []
      }
    ],
    "Body": {}
  },
  "Response": {
    "StatusCode": 205,
    "BodyAsJson": { "msg": "Hello world!!" },
    "BodyAsJsonIndented": true,
    "UseTransformer": true,
    "Headers": {
      "Transformed-Postman-Token": "token is {{request.headers.Postman-Token}}",
      "Content-Type": "application/json"
    }
  }
}

DELETE /__admin/mappings/{guid}

Delete a single stub mapping.

POST /__admin/mappings/save

Save all persistent stub mappings to the backing store

/__admin/requests

Logged requests and responses received by the mock service.

GET /__admin/requests

Get received requests

DELETE /__admin/requests

Delete all received requests

GET /__admin/requests/{guid}

Get a single request.

POST /__admin/requests/count --> TODO

POST /__admin/requests/find

Find requests based on a criteria.

Example request:

{
  "Path": {
        "Matchers": [
          {
            "Name": "WildcardMatcher",
            "Pattern": "/testjson"
          }
        ]
      }
}

GET /__admin/requests/unmatched --> TODO

GET /__admin/requests/unmatched/near-misses --> TODO

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.