goodeggs / resource-client

Easily create api clients for your server side resources. Inspired by Angular Resource.
MIT License
1 stars 0 forks source link

JSON Schema Validation #4

Closed dannynelson closed 9 years ago

dannynelson commented 9 years ago

Now supports optional JSON schema validation for url params, query params, request body, and response body. To use, pass the JSON schema into the configuration like so:

var Product = resourceClient({
  url: 'http://www.mysite.com/api/products/:_id',
  // recommended that you ban unkown properties when testing.
  banUnknownProperties: settings.env === 'test'
});

Product.action('update', {
  method: 'PUT'
  urlParamsSchema: require('./product/schemas/update/url_params.json')
  queryParamsSchema: require('./product/schemas/update/query_params.json')
  requestBodySchema: require('./product/schemas/update/request_body.json')
  responseBodySchema: require('./product/schemas/update/response_body.json')
})

It will reject / error if request validation fails.

makebbekus commented 9 years ago

:+1: