Welcome to db2rest’s documentation!

README:

This is the README file here.

db2rest

A HTTP REST API for relational databases

copyright:
  1. 2013 by Functional Genomic Center Zurich, Nicola Palumbo.
license:

MIT, see LICENSE for more details.

db2rest.app

This modules provide the main class of the application

class db2rest.app.DB2Rest(db_engine, host, port, log, ldap)[source]
dispatch_request(request)[source]

Responsible for dispatching the request.

TODO : the API class should not recevive the request object but a dict with paramets

wsgi_app(environ, start_response)[source]

Build the request from enviroment, invoke the dispatcher and eventually, return the response object.

db2rest.app.create_app(config_file)[source]

Create the app and the db engine given the configuration file

db2rest.app.initialize_ldap(string_connection, query)[source]

Initialize the connection with the LDAP server provided the connection string

db2rest.app.create_logger(level)[source]

Create the logger for the application given the level

db2rest.app.start()[source]

Start the app

db2rest.app.create_map(db_engine)[source]

Create a map between the database schema and the application - Each table in the database will be first level of the hiearachy - Each row will be the second level

db2rest.db

This module provide the interfaces with the dababase.

It uses SQLAlchemy to connect and introspect a RDBMS

class db2rest.db.DBAdapter(db_engine)[source]

Responsible to adapt the database.

add_row(table_name, values)[source]

Add a row to a table #: table_name #: values

delete_row(table_name, row_id)[source]

Delete row from a table #: table_name #: values

get_headers(table_name)[source]

Return the column name of a given table.

get_row(table_name, row_id)[source]

Returns a list with a row found.

get_rows(table_name)[source]

Return all the rows a given table.

TODO: Should be improved with the possibility to filter the rows by some criteria

get_tables()[source]

Return all the tables in the DB.

update_row(table_name, row_id, values)[source]

Update the given row_id in the given table.

db2rest.rest

class db2rest.rest.RestAPI(db_adapter)[source]

This is the class invoked by the dispatcher and it provides the 4 operation POST,GET,DELETE,PUT

TODO: Should be refactored

delete(request, params)[source]

Invoked when on a DELETE request.

get(request, params)[source]

Invoked when on a GET request.

post(request, params)[source]

Invoked when on a POST request.

put(request, params)[source]

Invoked when on a PUT request.

class db2rest.rest.Row(db_adapter, req, params)[source]

View of a single row.

delete()[source]
name = 'Row'
template_name = 'Table'
update()[source]
valid_methods = ['get', 'put', 'delete']
class db2rest.rest.Table(db_adapter, req, params)[source]

View on a single table

create_html()[source]

Extract the values from the html request and create the resource.

create_json()[source]

Extracts the values from the json request and create the resource.

get_html()[source]
get_json()[source]
name = 'Table'
template_name = 'Table'
valid_methods = ['get', 'post']
class db2rest.rest.Tables(db_adapter, req, params)[source]

View of a list of tables.

create()[source]
get()[source]
name = 'Tables'
template_name = 'Tables'
valid_methods = ['get']
class db2rest.rest.View(db_adapter, req, params)[source]

A view on a resource

db2rest.exceptions

exception db2rest.exceptions.HTTPExceptionMixin(description=None, response=None)[source]

In order to be rest complaint redefine some method of werkzeug HTTPException.

body_message[source]

The subclass is repsonsible to impleement this method.

get_body(environ=None)[source]

Return the body with the right message in case of json request.

get_response(environ)[source]

Return a json response for a json request otherwise an html response

exception db2rest.exceptions.MethodNotAllowed(description, valid_methods, method)[source]

Return a proper messagge error for not allowed operation.

body_message[source]
exception db2rest.exceptions.NotFound(description=None, response=None)[source]

Return a praper body message for not found resource

body_message[source]
exception db2rest.exceptions.Unauthorized(description=None, response=None)[source]

Return a praper body message and headers for unauthorized requests.

body_message[source]
get_headers(enviro)[source]

db2rest.helpers

db2rest.helpers.create_response(request, row_id)[source]

Creates the post response.

db2rest.helpers.delete_response(request)[source]

Creates a delete response.

db2rest.helpers.extract_file_ext(request)[source]

Extracts file extension either from a request, or enviroment.

db2rest.helpers.extract_table_name(request)[source]

Extracts the table name from the request.path.

db2rest.helpers.extract_table_row_id(uri)[source]

Returns the table name and row id from a string.

db2rest.helpers.is_json_request(request)[source]

Returns true is the best accept mimetype is json.

db2rest.helpers.update_response(request, data)[source]

Creates a update response.

Indices and tables

Table Of Contents

This Page