1.0.7 • Published 3 years ago

akera-rest-crud v1.0.7

Weekly downloads
4
License
MIT
Repository
github
Last release
3 years ago

Akera Logo

REST database access module (CRUD) for Akera.io web service - used by rest explorer module and other mobile/web clients this broker middleware service provides access to connected databases on the application server. Both meta-data information (database structure) and create/read/update/delete (CRUD) operations are supported.

Installation

$ npm install akera-rest-crud

Docs

Quick Start

This module is designed to only be loaded as broker level service which is usually done by adding a reference to it in services section of each broker's configuration in akera-web.json configuration file.

  "brokers": [
  	{	"name": "demo",
  		"host": "localhost",
		"port": 3737,
		"services": [
			{ 
				"middleware": "akera-rest-crud",
				"config": {
					"route": "/rest-crud/"
				}
			}
		]
	}
  ]

Service options available: - route: the route where the service is going to be mounted (default: '/rest/crud/')

The interface can then be used to retrieve meta-data information about connected databases, create/read/update/delete records from those databases by making HTTP requests:

MethodUrlFunctionResult
GEThttp://[host]/[broker]/rest-crud/[db]/[table]reads records from database table, optional query parameters (filter, sort, limit, offset) can be sent using the filter parameter through the HTTP query stringHTTP 404 if no record found, JSON object if only one record found or array if multiple
GEThttp://[host]/[broker]/rest-crud/[db]/[table]/[id](/[id])*reads a single record from database table, primary key field(s) values should be sent as URL segments in the same order as in the primary index definitionHTTP 404 if record not found, JSON object if found
GEThttp://[host]/[broker]/rest-crud/[db]/[table]/countreturns number of records from database table, optional query filter can be sent using the filter parameter through the HTTP query stringJSON object with num property holding the number of records
POSThttp://[host]/[broker]/rest-crud/[db]/[table]create a new record in database table, the request body should be a JSON object holding values to be set for each table's fieldsHTTP 500 if error on create, JSON object with full table record (fields might be set in database triggers)
PUThttp://[host]/[broker]/rest-crud/[db]/[table]/rowid/[id]update a record in database table using the ROWID value sent as last URL segment and the request body should be a JSON object holding values to be set for each table's fieldsHTTP 404 if record not found, HTTP 500 if error on update, JSON object with full table record (fields might be updated in database triggers)
PUThttp://[host]/[broker]/rest-crud/[db]/[table]/[id](/[id])*update a record in database table, primary key field(s) values should be sent as URL segments and the request body should be a JSON object holding values to be set for each table's fieldsHTTP 404 if record not found, HTTP 500 if error on update, JSON object with full table record (fields might be updated in database triggers)
DELETEhttp://[host]/[broker]/rest-crud/[db]/[table]/rowid/[id]delete a record from database table, primary key field(s) values should be sent as URL segmentsHTTP 404 if record not found, HTTP 500 if error on delete, JSON object with num property holding the number of records deleted
DELETEhttp://[host]/[broker]/rest-crud/[db]/[table]/[id](/[id])*delete a record from database table using the ROWID value sent as last URL segmentHTTP 404 if record not found, HTTP 500 if error on delete, JSON object with num property holding the number of records deleted
GEThttp://[host]/[broker]/rest-crud/metareturns the list of connected databasesJSON array with one string entry for each connected database containing the database logical name
GEThttp://[host]/[broker]/rest-crud/meta/[db]returns the list of database's tables, db parameter can be either the database name or zero-base indexHTTP 404 if database not found, JSON array with one string entry for each database table containing the table name
GEThttp://[host]/[broker]/rest-crud/meta/[db]/[table]returns database table's field information, table parameter can be either the database name or zero-base indexHTTP 404 if table not found, JSON array with one entry for each table field
GEThttp://[host]/[broker]/rest-crud/meta/[db]/[table]/indexreturns database table's indexes information, table parameter can be either the database name or zero-base indexHTTP 404 if table not found, JSON array with one entry for each table index

License

MIT

1.0.7

3 years ago

1.0.5

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago