Catmandu::Plack::unAPI - unAPI webservice based on Catmandu
Catmandu::Plack::unAPI implements an unAPI web service as PSGI application.
Set up an app.psgi for instance to get data via http://arxiv.org identifier using Catmandu::Importer::ArXiv:
app.psgi
use Catmandu::Plack::unAPI; use Catmandu::Importer::ArXiv; Catmandu::Plack::unAPI->new( query => sub { my ($id) = @_; return if $id !~ qr{^(arXiv:)?[0-9abc/.]+}i; Catmandu::Importer::ArXiv->new( id => $id )->first; } )->to_app;
Retrieving items from a Catmandu::Store is even simpler:
Catmandu::Plack::unAPI->new( store => $store )->to_app;
Start the application, e.g. with plackup app.psgi and query via unAPI:
plackup app.psgi
curl 'localhost:5000' curl 'localhost:5000?id=1204.0492&format=json'
Code reference with a query method to get an item (as reference) by a given identifier (HTTP request parameter id). If the method returns undef, the application returns HTTP 404. If the methods returns a scalar, it is used as error message for HTTP response 400 (Bad Request).
id
Instance of Catmandu::Store or store name and options as array reference to query items from.
Hash reference with format names mapped to MIME type, Catmandu::Exporter configuration and (optional) documentation for each format. By default only JSON and YAML are configured as following:
json => { type => 'application/json', exporter => [ 'JSON', pretty => 1 ], docs => 'http://json.org/' }, yaml => { type => 'text/yaml', exporter => [ 'YAML' ], docs => 'http://en.wikipedia.org/wiki/YAML' }
An exporter is instanciated for each request, so performance may be low depending on configuration.
The error response is always text/plain, this may be configurable in a future release.
text/plain
Timeouts are not implemented yet.
Jakob Voß <jakob.voss@gbv.de>
Copyright 2014- Jakob Voß
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Catmandu::Plack::unAPI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Catmandu::Plack::unAPI
CPAN shell
perl -MCPAN -e shell install Catmandu::Plack::unAPI
For more information on module installation, please visit the detailed CPAN module installation guide.