# Response details

2020-10-19

## Intro

The Response represents the most important entity in the mocking system as it gives you a lot of flexibility to simulate different scenarios in your system.

## Fields

The fields available when defining a response are Name, Status, Default Response flag, Conditions, Header and Body mirroring, Response Headers, Response Body and Response latency. These combined can give you huge control over how the route behaves depending on the given Request. You can add error pages that are returned when certain conditions are met, such as missing or invalid Headers, such as missing or invalid Body values or when your Route is accessed from an invalid Origin.

## Mirroring

When you wish to test your code you may want to see what you are actually sending to the backend, for this use can use mirroring. When mirroring is activated, no matter what you set for Response Headers or Body you will always get the same data that you have sent to the endpoint.

Here you define the response headers. You are presented by two default inputs which you can use to set your first response header. You can add new headers by clicking on the + Add another button or remove existing ones by clicking on Remove. These values will be returned when the response is matched.

## Body

The Body is where you define the response Body. You are presented with the JSON editor which makes it easier for you to lint your code and visually understand the structure.

## Data Generators

You can use data generator syntax in the response body to get a randomized response every time. Available generator values are:

$$fullName$$ - Generates a full name $$name$$ - Alias, generates a full name $$firstName$$ - Generates a first name $$lastName$$ - Generates a last name $$companyName$$ - Generates a company name $$company$$ - Generates a company name $$product$$ - Generates a product name $$country$$ - Generates a country name $$gender$$ - Generates a random gender $$month$$ - Generates a random month string $$email$$ - Generates a random email $$description$$ - Generates a random description string $$password$$ - Generates a random password $$state$$ - Generates a random US state $$address$$ - Generates a random address

You use these values in the following way:

{
"User": {
"name": "$$name$$",
"company": "$$company$$"
}
}


## Conditions

Defining conditions empowers you to have multiple responses for the same route. You want to test negative paths, like a missing parameter, or test positive paths like creating multiple resources. This can be easily accomplished with response conditions.

Response conditions are a JSON object that defines what to look for in your request. You can define Header based conditions, Body based conditions and Origin based conditions. The condition is defined by it’s Source, Kind and Value properties.

Source represents the holder of the information to verify. For headers it’s the header name. For body depending on the content-type header it can be the JSON Path to the property, or the form name value. There are also two special values $$body$$ (which seeks through the entire body) and $$size$$ (which runs comparison against the body size). For the origin it’s not used because we analyze the Origin header from the request. The Kind property represents the comparison for the value. It can be of the following values:

* exists
* nexists
* eq
* contains
* neq
* ncontains
* gt
* lt


The gt and lt are only used with the special value $$size$$ and the rest are used for all of the other conditions. The Value holds the required value the request will be compared against. If you set multiple conditions as of right now they will be treated as AND conditions. The first response with most satisfying conditions is selected. If you have multiple responses with x matching conditions the first one matched will be returned. If you have no responses satisfying the criteria the default response will be used.

## Base64 encoding

The last but not least you have the ability to add binary responses. You can achieve this by encoding them in base 64 with padding and using that as the response. Just know that it would be best to add appropriate headers, like content-type so that the browser knows what’s going on.

Nenad Lukic Founder of Mockadillo and a firm believer in reducing any sources of friction and frustrations in the workplace.