1 # HAR Validator [![version][npm-version]][npm-url] [![License][npm-license]][license-url]
3 Extremely fast HTTP Archive ([HAR](http://www.softwareishard.com/blog/har-12-spec/)) validator using JSON Schema.
5 [![Build Status][travis-image]][travis-url]
6 [![Downloads][npm-downloads]][npm-url]
7 [![Code Climate][codeclimate-quality]][codeclimate-url]
8 [![Coverage Status][codeclimate-coverage]][codeclimate-url]
9 [![Dependencies][david-image]][david-url]
15 npm install --global har-validator
18 npm install --save har-validator
25 Usage: har-validator [options] <files ...>
29 -h, --help output usage information
30 -V, --version output the version number
31 -s, --schema [name] validate schema name (log, request, response, etc ...)
38 har-validator har.json
40 har-validator --schema request request.json
45 **Note**: as of [`v2.0.0`](https://github.com/ahmadnassri/har-validator/releases/tag/v2.0.0) this module defaults to Promise based API. *For backward comptability with `v1.x` an [async/callback API](#callback-api) is provided*
49 > Returns a promise that resolves to the valid object.
51 - **data**: `Object` *(Required)*
52 a full [HAR](http://www.softwareishard.com/blog/har-12-spec/) object
56 .then(data => console.log('horray!'))
60 ### Validate.log(data)
62 > Returns a promise that resolves to the valid object.
64 - **data**: `Object` *(Required)*
65 a [log](http://www.softwareishard.com/blog/har-12-spec/#log) object
69 .then(data => console.log('horray!'))
73 ### Validate.cache(data)
75 > Returns a promise that resolves to the valid object.
77 - **data**: `Object` *(Required)*
78 a [cache](http://www.softwareishard.com/blog/har-12-spec/#cache) object
82 .then(data => console.log('horray!'))
86 ### Validate.cacheEntry(data)
88 > Returns a promise that resolves to the valid object.
90 - **data**: `Object` *(Required)*
91 a ["beforeRequest" or "afterRequest"](http://www.softwareishard.com/blog/har-12-spec/#cache) objects
94 validate.cacheEntry(data)
95 .then(data => console.log('horray!'))
99 ### Validate.content(data)
101 > Returns a promise that resolves to the valid object.
103 - **data**: `Object` *(Required)*
104 a [content](http://www.softwareishard.com/blog/har-12-spec/#content) object
107 validate.content(data)
108 .then(data => console.log('horray!'))
109 .catch(console.error)
112 ### Validate.cookie(data)
114 > Returns a promise that resolves to the valid object.
116 - **data**: `Object` *(Required)*
117 a [cookie](http://www.softwareishard.com/blog/har-12-spec/#cookies) object
120 validate.cookie(data)
121 .then(data => console.log('horray!'))
122 .catch(console.error)
125 ### Validate.creator(data)
127 > Returns a promise that resolves to the valid object.
129 - **data**: `Object` *(Required)*
130 a [creator](http://www.softwareishard.com/blog/har-12-spec/#creator) object
133 validate.creator(data)
134 .then(data => console.log('horray!'))
135 .catch(console.error)
138 ### Validate.entry(data)
140 > Returns a promise that resolves to the valid object.
142 - **data**: `Object` *(Required)*
143 an [entry](http://www.softwareishard.com/blog/har-12-spec/#entries) object
147 .then(data => console.log('horray!'))
148 .catch(console.error)
151 ### Validate.log(data)
153 alias of [`Validate(data)`](#validate-data-callback-)
155 ### Validate.page(data)
157 > Returns a promise that resolves to the valid object.
159 - **data**: `Object` *(Required)*
160 a [page](http://www.softwareishard.com/blog/har-12-spec/#pages) object
164 .then(data => console.log('horray!'))
165 .catch(console.error)
168 ### Validate.pageTimings(data)
170 > Returns a promise that resolves to the valid object.
172 - **data**: `Object` *(Required)*
173 a [pageTimings](http://www.softwareishard.com/blog/har-12-spec/#pageTimings) object
176 validate.pageTimings(data)
177 .then(data => console.log('horray!'))
178 .catch(console.error)
181 ### Validate.postData(data)
183 > Returns a promise that resolves to the valid object.
185 - **data**: `Object` *(Required)*
186 a [postData](http://www.softwareishard.com/blog/har-12-spec/#postData) object
189 validate.postData(data)
190 .then(data => console.log('horray!'))
191 .catch(console.error)
194 ### Validate.record(data)
196 > Returns a promise that resolves to the valid object.
198 - **data**: `Object` *(Required)*
199 a [record](http://www.softwareishard.com/blog/har-12-spec/#headers) object
202 validate.record(data)
203 .then(data => console.log('horray!'))
204 .catch(console.error)
207 ### Validate.request(data)
209 > Returns a promise that resolves to the valid object.
211 - **data**: `Object` *(Required)*
212 a [request](http://www.softwareishard.com/blog/har-12-spec/#request) object
215 validate.request(data)
216 .then(data => console.log('horray!'))
217 .catch(console.error)
220 ### Validate.response(data)
222 > Returns a promise that resolves to the valid object.
224 - **data**: `Object` *(Required)*
225 a [response](http://www.softwareishard.com/blog/har-12-spec/#response) object
228 validate.cacheEntry(data)
229 .then(data => console.log('horray!'))
230 .catch(console.error)
233 ### Validate.timings(data)
235 > Returns a promise that resolves to the valid object.
237 - **data**: `Object` *(Required)*
238 a [timings](http://www.softwareishard.com/blog/har-12-spec/#timings) object
241 validate.timings(data)
242 .then(data => console.log('horray!'))
243 .catch(console.error)
250 ### Validate(data [, callback])
252 > Returns `true` or `false`.
255 var HAR = require('./har.json');
256 var validate = require('har-validator/lib/async');
258 validate(HAR, function (e, valid) {
259 if (e) console.log(e.errors)
261 if (valid) console.log('horray!');
265 The async API provides exactly the same methods as the [Promise API](#promise-api)
271 Donations are welcome to help support the continuous development of this project.
273 [![Gratipay][gratipay-image]][gratipay-url]
274 [![PayPal][paypal-image]][paypal-url]
275 [![Flattr][flattr-image]][flattr-url]
276 [![Bitcoin][bitcoin-image]][bitcoin-url]
280 [ISC License](LICENSE) © [Ahmad Nassri](https://www.ahmadnassri.com/)
282 [license-url]: https://github.com/ahmadnassri/har-validator/blob/master/LICENSE
284 [travis-url]: https://travis-ci.org/ahmadnassri/har-validator
285 [travis-image]: https://img.shields.io/travis/ahmadnassri/har-validator.svg?style=flat-square
287 [npm-url]: https://www.npmjs.com/package/har-validator
288 [npm-license]: https://img.shields.io/npm/l/har-validator.svg?style=flat-square
289 [npm-version]: https://img.shields.io/npm/v/har-validator.svg?style=flat-square
290 [npm-downloads]: https://img.shields.io/npm/dm/har-validator.svg?style=flat-square
292 [codeclimate-url]: https://codeclimate.com/github/ahmadnassri/har-validator
293 [codeclimate-quality]: https://img.shields.io/codeclimate/github/ahmadnassri/har-validator.svg?style=flat-square
294 [codeclimate-coverage]: https://img.shields.io/codeclimate/coverage/github/ahmadnassri/har-validator.svg?style=flat-square
296 [david-url]: https://david-dm.org/ahmadnassri/har-validator
297 [david-image]: https://img.shields.io/david/ahmadnassri/har-validator.svg?style=flat-square
299 [gratipay-url]: https://www.gratipay.com/ahmadnassri/
300 [gratipay-image]: https://img.shields.io/gratipay/ahmadnassri.svg?style=flat-square
302 [paypal-url]: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=UJ2B2BTK9VLRS&on0=project&os0=har-validator
303 [paypal-image]: http://img.shields.io/badge/paypal-donate-green.svg?style=flat-square
305 [flattr-url]: https://flattr.com/submit/auto?user_id=ahmadnassri&url=https://github.com/ahmadnassri/har-validator&title=har-validator&language=&tags=github&category=software
306 [flattr-image]: http://img.shields.io/badge/flattr-donate-green.svg?style=flat-square
308 [bitcoin-image]: http://img.shields.io/badge/bitcoin-1Nb46sZRVG3or7pNaDjthcGJpWhvoPpCxy-green.svg?style=flat-square
309 [bitcoin-url]: https://www.coinbase.com/checkouts/ae383ae6bb931a2fa5ad11cec115191e?name=har-validator