# 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 10

### 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 197

##### Returns:

Type
  JsonCachingProxy

#### addBodyParser() → {JsonCachingProxy}

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

Source:
  - index.js, line 262

##### 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 281

##### 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 164

##### 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 246

##### 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 334

##### 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 60

##### 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 105

##### 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 88

##### 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 69

##### Returns:

A unique key, hash tuple that identifies the request

Type
  Object

#### getApp() → {Object}

Returns the Express App

Source:
  - index.js, line 432

##### Returns:

Type
  Object

#### getDefaultOptions() → {Object}

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

Source:
  - index.js, line 426

##### Returns:

Type
  Object

#### getExcludedParamMap() → {Object}

Returns the key value map of all the excluded params

Source:
  - index.js, line 444

##### Returns:

Type
  Object

#### getOptions() → {Object}

Returns the options passed into the proxy

Source:
  - index.js, line 420

##### Returns:

Type
  Object

#### getServer() → {Object}

Returns the Node server object

Source:
  - index.js, line 438

##### Returns:

Type
  Object

#### getTotalCachedRoutes() → {number}

Count of total cached routes in memory

Source:
  - index.js, line 450

##### Returns:

Type
  number

#### isRecording() → {JsonCachingProxy}

Is the server saving to the cache

Source:
  - index.js, line 468

##### Returns:

Type
  JsonCachingProxy

#### isReplaying() → {boolean}

Is the server sending us cached responses

Source:
  - index.js, line 462

##### Returns:

Type
  boolean

#### isRouteCacheEmpty() → {boolean}

Determines if we have anything in the cache

Source:
  - index.js, line 456

##### 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 155

##### Returns:

Whether the test is true for some matcher

Type
  boolean

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

Start the server and generate any log output if needed

##### Parameters:

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

Source:
  - index.js, line 370

##### Returns:

Type
  JsonCachingProxy

#### stop() → {JsonCachingProxy}

Stops the proxy server

Source:
  - index.js, line 407

##### Returns:

Type
  JsonCachingProxy