-
-
06 Oct 2017 01:34:12 UTC
- Distribution: Catalyst-ActionRole-JSV
- Module version: 0.03
- Source (raw)
- Browse (raw)
- Changes
- Homepage
- How to Contribute
- Repository
- Issues (0)
- Testers (394 / 0 / 0)
- Kwalitee
Bus factor: 0- 100.00% Coverage
- License: perl_5
- Activity
24 month- Tools
- Download (10.88KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
NAME
Catalyst::ActionRole::JSV - A JSON Schema validator for Catalyst actions
SYNOPSIS
package MyApp::Controller::Item; use Moose; use namespace::autoclean; BEGIN { extends 'Catalyst::Controller'; } # RESTful API (Consumes type action) support by Catalyst::Runtime 5.90050 higher __PACKAGE__->config( action => { '*' => { Consumes => 'JSON', Path => '', } } ); # Get info on a specific item # GET /item/:item_id sub lookup :GET Args(1) :Does(JSV) :JSONSchema(root/schema/lookup.json) { my ( $self, $c, $item_id ) = @_; my $params = $c->request->parameters; ... } # lookup.json (json schema draft4 validation) { "title": "Lookup item", "type": "object", "properties": { "item_id": { "type": "integer", "minLength": 1, "maxLength": 9, "captureargs": 1 # In the case of URL CaptureArgs }, "paramX": { "type": "string", "minLength": 8, "maxLength": 12 }, }, "required": ["item_id"] }
DESCRIPTION
Catalyst::ActionRole::JSV is JSON Schema validator for Catalyst actions. Internally use the json schema draft4 validator called JSV.
Error Response
On error it returns 400 http response status. The stash key to set the error message is 'View::JSON expose_stash' key. The default key if omitted is 'json'.
$c->stash->{'View::JSON expose_stash key'} = {message => 'JSV->validate->get_error'}
myapp.yml config
name: MyApp View::JSON: expose_stash: 'json'
SEE ALSO
Catalyst Advent Calendar 2013 / How to implement a super-simple REST API with Catalyst http://www.catalystframework.org/calendar/2013/26
AUTHOR
Masaaki Saito <masakyst.public@gmail.com>
COPYRIGHT
Copyright 2017- Masaaki Saito
LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
SEE ALSO
Module Install Instructions
To install Catalyst::ActionRole::JSV, copy and paste the appropriate command in to your terminal.
cpanm Catalyst::ActionRole::JSV
perl -MCPAN -e shell install Catalyst::ActionRole::JSV
For more information on module installation, please visit the detailed CPAN module installation guide.