NAME
Hyle
DESCRIPTION
Simple REST API interface to the database backend using Plack and DBIx::Class
WARNING: This is APLHA quality software.
SYNOPSIS
# cpanm Hyle
# hyle.pl --dsn'dbi::SQLite::dbname=file.db' --username=... --password= ....
# curl http://localhost:8000/collection/id/7
# curl -X DELETE ...
# ....
#
# more configuration
my $schema = DBIx::Class->connect(...);
my $app = Hyle->new(
schema => $schema,
... other options ...
);
# make a custom mount with plack::builder ....
builder {
mount => "/somewhere" => $app;
mount => /somethingElse" => $other_app;
};
HTTP Methods
GET
POST - update/create
DELETE
HEAD
OBJECT ATTRIBUTES
serializers
%serializers = (
"application/json" => sub { ... },
...,
);
defaults to 'data/json', response content type and JSON::encode_json serialization function.
override
%overrides = (
'artist' => { GET => sub { ... } },
...,
);
allows overriding particular methods.
if the class itself implements the __GET() __POST() __DELETE etc., methods, those will be invoked first, then followed by the check for an appropriate method in the %overrides hash, if no method is found, the default ( Hyle::__GET, etc.) implementation will be used.
result_sources
%result_sources = (
artist => 1,
cds => 1,
...
);
Expose only the following result sources in the api.
allow_post_updates
If true, the POST will either create or update an existing resource. It's false by default, on conflict with an existing respource, a 409 HTTP response is returned.
Support for JSONP
this module is able to include information about potential methods of a result source, or any other subref implementing it.
i.e.
my $jsonp_method :JSONP = sub { my ($self,$req,$resultset,$rs,$jsonp_method_name,@args) = @_;
$rs->search_where({
column => { -in => [ \@args ] },
});
# ....
my $response = $req->new_response(200);
$response->body( $self->serializer( ... ) );
};
GET http://localhost:3000/artist/id/7
200 OK
{ "a": 1, "b":2, "__jsonp_methods:["foo"] }
var someFancyObject = { ... }; someFancyObject.foo = function( ) { ... };
var ret = someFancyObject.foo({ meh => 1 },{ callback => function() { ... }} );
POST http://localhost:8000/artist/id/7?jsonp=foo&jsonp_callback=gotData
foo: 1
COPYRIGHT AND LICENCE
Copyright (C) 2014 Tomasz Czepiel
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.1 or, at your option, any later version of Perl 5 you may have available.