1.2.0 • Published 9 years ago

timplan v1.2.0

Weekly downloads
15
License
MIT
Repository
github
Last release
9 years ago

Timplan - JSONSchema validation for hapi

Timplan allows you to use JSON schemas instead of joi in hapi. It's still possible to use hapi for validation. So one possible strategy could be to let path and query parameter validation remain in joi, but use schemas for payload and response.

Example

var lib = {
  hapi: require('hapi'),
  timplan: require('timplan')
};

// Set up a validator
var validator = new lib.timplan.Validator({
  baseUrl: 'http://api.bloglovin.se/schemas/',
  schemaDir: './schemas'
});
// Add the schemas that we will use
validator.addYamlSchema('requests/get-post-1.0.0.schema.yml');
validator.addSchema('post-1.0.0.schema.json');

var server = new lib.hapi.Server('localhost', 8000, { cors: true });

server.route({
  method: 'GET',
  path: '/posts/{id}',
  handler: function serveSampleData(request, reply) {
    var post = require('./docs/schemas/sample/data/post-2305151223.json');
    reply(post);
  },
  config: {
    validate: validator.request('requests/get-post-1.0.0.schema.json'),
    response: {
      schema: validator.response('post-1.0.0.schema.json')
    }
  }
});

server.start(function serverStarted() {
  console.log("We're up and running");
});
1.2.0

9 years ago

1.1.0

9 years ago

1.0.0

9 years ago

0.5.3

10 years ago

0.5.2

10 years ago

0.5.1

10 years ago

0.5.0

10 years ago

0.4.0

10 years ago

0.3.0

10 years ago

0.2.1

10 years ago