# Class: JsonCachingProxy

## JsonCachingProxy(options)

The caching proxy server.

## Constructor

#### new JsonCachingProxy(options)

##### Parameters:

Name | Type | Description
--- | --- | ---
`options` | Object | Options passed into the ctor will override defaults if defined

Source:
  - index.js, line 14

### Methods

#### addAdminRoutes() → {JsonCachingProxy}

Add the admin express routes for controlling the proxy server through a browser. Allows one to make GET requests to clear the cache, disable/enable playback/recording, and generate a har file of the cache to download for later use.

Source:
  - index.js, line 218

##### Returns:

Type
  JsonCachingProxy

#### addBodyParser() → {JsonCachingProxy}

Add Request body parsing into RAW if there is actual body content

Source:
  - index.js, line 283

##### Returns:

Type
  JsonCachingProxy

#### addCachingRoute() → {JsonCachingProxy}

An express route that reads from the cache if possible for any routes persisted in cache memory

Source:
  - index.js, line 302

##### Returns:

Type
  JsonCachingProxy

#### addHarEntriesToCache(harObject) → {JsonCachingProxy}

Add express routes for each entry in a harObject. The harObject would have been read in from a har file at some point

##### Parameters:

Name | Type | Description
--- | --- | ---
`harObject` | Object | A standard HAR file object that contains a collection of entries

Source:
  - index.js, line 185

##### Returns:

Type
  JsonCachingProxy

#### addMiddleWareRoutes(middlewareList) → {JsonCachingProxy}

Add user supplied middleware routes to express in order to handle special cases (browser-sync middleware options)

##### Parameters:

Name | Type | Description
--- | --- | ---
`middlewareList` | Array.<Object> | A list of route/handler pairs

Source:
  - index.js, line 267

##### Returns:

Type
  JsonCachingProxy

#### addProxyRoute() → {JsonCachingProxy}

Add the proxy route that makes the actual request to the target server and cache the response when it comes back. Modifies locations on redirects.

Source:
  - index.js, line 355

##### Returns:

Type
  JsonCachingProxy

#### convertToNameValueList(obj) → {Array.<Object>}

Returns an Object's own properties into an array of name-value pair objects

##### Parameters:

Name | Type | Description
--- | --- | ---
`obj` | Object |

Source:
  - index.js, line 81

##### Returns:

Type
  Array.<Object>

#### createHarEntry(startedDateTime, req, res, data) → {Object}

Build a HAR entry object from an express Request and response

##### Parameters:

Name | Type | Description
--- | --- | ---
`startedDateTime` | string | An ISO Datetime String
`req` | Object | An express IncomingMessage request
`res` | Object | An express ServerResponse response
`data` | Object | An express response body (the content)

Source:
  - index.js, line 126

##### Returns:

A HAR entry object

Type
  Object

#### genKeyFromExpressReq(req) → {string}

Takes a generic express request and convert it into a HAR request so that a unique key can be generated

##### Parameters:

Name | Type | Description
--- | --- | ---
`req` | Object | An express IncomingMessage request

Source:
  - index.js, line 109

##### Returns:

A unique hash key that identifies the request

Type
  string

#### genKeyFromHarReq(harEntryReq) → {Object}

Generate a unique hash key from a har file entry's request object: TODO: Include headers?

##### Parameters:

Name | Type | Description
--- | --- | ---
`harEntryReq` | Object | HAR request object

Source:
  - index.js, line 90

##### Returns:

A unique key, hash tuple that identifies the request

Type
  Object

#### getApp() → {Object}

Returns the Express App

Source:
  - index.js, line 460

##### Returns:

Type
  Object

#### getDefaultOptions() → {Object}

Returns the default options that are used when no options are passed in

Source:
  - index.js, line 454

##### Returns:

Type
  Object

#### getExcludedParamMap() → {Object}

Returns the key value map of all the excluded params

Source:
  - index.js, line 472

##### Returns:

Type
  Object

#### getOptions() → {Object}

Returns the options passed into the proxy

Source:
  - index.js, line 448

##### Returns:

Type
  Object

#### getServer() → {Object}

Returns the Node server object

Source:
  - index.js, line 466

##### Returns:

Type
  Object

#### getTotalCachedRoutes() → {number}

Count of total cached routes in memory

Source:
  - index.js, line 478

##### Returns:

Type
  number

#### isRecording() → {JsonCachingProxy}

Is the server saving to the cache

Source:
  - index.js, line 496

##### Returns:

Type
  JsonCachingProxy

#### isReplaying() → {boolean}

Is the server sending us cached responses

Source:
  - index.js, line 490

##### Returns:

Type
  boolean

#### isRouteCacheEmpty() → {boolean}

Determines if we have anything in the cache

Source:
  - index.js, line 484

##### Returns:

Type
  boolean

#### isRouteExcluded(method, uri) → {boolean}

Check to see if the pieces of a request are excluded. This checks only the method and the uri. It uses the list of regExp matchers to test

##### Parameters:

Name | Type | Description
--- | --- | ---
`method` | string | e.g. GET, POST, PUT, etc.
`uri` | string | e.g. http://www.api.com/rest/accounts

Source:
  - index.js, line 176

##### Returns:

Whether the test is true for some matcher

Type
  boolean

#### removeCookiesDomain(cookies) → {Array.<Object>}

Remove the domain portion of any cookies from the object

##### Parameters:

Name | Type | Description
--- | --- | ---
`cookies` | Object | Express cookies array

Source:
  - index.js, line 61

##### Returns:

- Cookies with domain portion removed

Type
  Array.<Object>

#### start(callback) → {JsonCachingProxy}

Start the server and generate any log output if needed

##### Parameters:

Name | Type | Description
--- | --- | ---
`callback` | function | fn executed after the server has started

Source:
  - index.js, line 395

##### Returns:

Type
  JsonCachingProxy

#### stop(callback) → {JsonCachingProxy}

Stops the proxy server

##### Parameters:

Name | Type | Description
--- | --- | ---
`callback` | function | fn executed after the server has stopped

Source:
  - index.js, line 435

##### Returns:

Type
  JsonCachingProxy