Logo
30 days challenge API Documentation

Create Server Stub

POST https://api.getpostman.com/mocks/{{mock_uid}}/server-responses

What's a server Stub?

Server level responses like 500, 503, etc. are agnostic of application-level logic. This server stub feature allows you to simulate the same behaviour on a mock server as you need not define 5xx errors individually for all paths exposed on your mock server. If you set one of the server stubs as active, then all the calls to the mock server will be returned with that active server stub's response.

Let's explore the functionality of this API -

This endpoint allows you to create a server response on a mock server.

Request body parameters:

  • name: This field defines the name of the server response. It's a required parameter.
  • statusCode: This field defines the response code that this server response will return. Only 5xx values are allowed for this field; you can read about them here. It's a required parameter.
  • headers: This field is an array of objects. Each object contains two fields, namely key and value. The key field is the header key, and the value field defines the corresponding value for the header key. e.g:
[
{
"key": "Content-Type",
"value": "application/json"
}
]

  • body: This field is a free string and will be returned as the response body when you hit the mock server.

Note: Multiple server responses can be created for a mock server but only one can be set as active at any point.

 

Body PARAM

Key Datatype Required Description 



HEADERS

Key Datatype Required Description 




RESPONSES

status OK

{ "createdAt": "2022-05-02T09:38:04.000Z", "updatedAt": "2022-05-02T09:38:04.000Z", "id": "7a2cd600-cf51-4e8a-b802-5e458828f4e5", "name": "Internal server error", "statusCode": 500, "headers": [ { "key": "Content-type", "value": "application/json" } ], "language": null, "body": "{\n \"message\": \"Something went wrong; please try again in some time.\"\n}", "createdBy": "1", "updatedBy": "1", "mock": "69105a6d-7f3e-4662-b116-f92dad8d9f06" }



Curl
curl -X POST 'https://api.getpostman.com/mocks/undefined/server-responses' -d '{"serverResponse":{"name":"Internal Server Error","statusCode":500,"headers":[{"key":"Content-Type","value":"application/json"}],"body":"{\n \"message\": \"Something went wrong; please try again in some time.\"\n}"}}'

ENDPOINTS