NAME

dbi2http - Export DBI database as HTTP API (Riap::HTTP)

VERSION

This document describes version 0.07 of dbi2http (from Perl distribution Plack-App-dbi2http), released on 2017-07-11.

SYNOPSIS

Simplest usage (will run an HTTP server):

% dbi2http dbi:SQLite:dbname=/path/to/your.db

To specify DBI user and password:

% dbi2http dbi:mysql:database=foo --user dbuser --pass dbpass

Unknown options will be passed to plackup:

% dbi2http dbi:mysql:test --user dbuser --pass dbpass --port 5001 -s Starman

See other options:

% dbi2http --help

After the server is running, you can query it from another console, e.g. via curl:

% curl http://localhost:5000/list_tables
countries
continents

% curl http://localhost:5000/list_columns?table=countries
id
ind_name
eng_name
tags

% curl 'http://localhost:5000/list_columns?table=countries&detail=1&-riap-fmt=json-pretty'
[
   200,
  "OK",
  [
     {
        "pos" : 1,
        "name" : "id",
        "type" : "text"
     },
     {
        "name" : "ind_name",
        "pos" : 2,
        "type" : "text"
     },
     {
        "type" : "text",
        "name" : "eng_name",
        "pos" : 3
     },
     {
        "pos" : 4,
        "name" : "tags",
        "type" : "text"
     }
  ]
]

% curl 'http://localhost:5000/list_rows?table=countries'
China   cn      Cina    panda
Indonesia       id      Indonesia       bali,tropical
Singapore       sg      Singapura       tropical
United States of America        us      Amerika Serikat

% curl 'http://localhost:5000/list_rows?table=countries&-riap-fmt=text-pretty'
.-----------------------------------------------------------------.
| eng_name                   id   ind_name          tags          |
|                                                                 |
| China                      cn   Cina              panda         |
| Indonesia                  id   Indonesia         bali,tropical |
| Singapore                  sg   Singapura         tropical      |
| United States of America   us   Amerika Serikat                 |
`-----------------------------------------------------------------'

Or use App::riap, a client shell for Riap (with filesystem-like API browsing and shell tab completion):

% riap http://localhost:5000/
riap /> ls
list_columns
list_rows
list_tables

riap /> list_tables
countries
continents

riap /> list_columns --table countries --detail

riap /> list_rows --table countries

DESCRIPTION

This is a one-liner shortcut to export your DBI database as HTTP API (using Riap::HTTP protocol). It is a wrapper to a PSGI app (Plack::App::dbi2http) which does the heavy-lifting. So what this script does is basically create a config file on-the-fly and run plackup to serve the PSGI application.

USAGE

% dbi2http [options] <DBI dsn>

OPTIONS

Unknown options will be passed to plackup.

--user => str

Supply DBI username. Some driver do not need it (e.g. SQLite).

--pass => str

Supply DBI password. Some driver do not need it (e.g. SQLite).

HOMEPAGE

Please visit the project's homepage at https://metacpan.org/release/Plack-App-dbi2http.

SOURCE

Source repository is at https://github.com/perlancar/perl-Plack-App-dbi2http.

BUGS

Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Plack-App-dbi2http

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

SEE ALSO

Plack::App::dbi2http, Riap, Riap::HTTP

AUTHOR

perlancar <perlancar@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2017, 2015, 2014 by perlancar@cpan.org.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.