A NodeJS Express based REST API that provides an interface to Google LevelDB. You may use an external JWT access token or native support to the Google access token for authentication and authorization.
Description:
This REST API provides an interface to LevelDB, a fast key-value storage library written at Google that provides an ordered mapping from string keys to string values. This API is implemented in Node.js and Express.js framework. User authentication is performed by the client application through the Google API. The returned access token authorizes access to the database corresponding to the user. The API can handle multiple databases simultaneously, identified by the user's email and stored in separate directories. The user's email is extracted from the valid access token.
Sharing database
It is also possible to share a single database among different users if database_name value is given
Features:
- Full CRUD (Create, Read, Update, Delete) operations for keys and values:
- Ability to create, read, update, and delete key-value pairs in LevelDB.
- Support for basic data types like string, number, and boolean.
- Filtering and pagination mechanisms:
- Filtering of query results by key or value. [TODO]
- Navigation through query results in a paginated manner. [TODO]
- Transaction support:
- Execute read/write operations in an atomic block.
- Ensure data consistency in case of failures.
- Multiple database management:
- Support for multiple concurrent LevelDB databases.
- Data isolation between different users.
- Database identification by user email.
Authentication:
User authentication is performed by the client application through the Google API. The returned access token must be sent with each request to the REST API.
Installation:
firewall ports:
sudo ufw allow 9090 # it requires reboot
- Clone the GitHub repository:
git clone https://github.com/your-username/leveldb-api.git - Install dependencies:
npm install - Start the API:
npm run start
Develop server with nodemon (hot reload)
- Start the API:
npm run dev
Debug mode (no authentication)
- Edit config/default.json 1.1 Set database_name property to a fixed the database name; 1.2 Set debug property to true
- Execute the server in dev mode
npm run dev - Open a new terminal and open the db connection by with a fake authentication:
curl -X GET -H "Authorization: Bearer anything" "http://localhost:9090/api/v1/auth" - Now you can make store requests to the authenticated database with the HTTP header: Authentication: mydb <database_name>
Usage:
The API can be used through HTTP requests. Please refer to the complete API documentation in the README.md file for more information on endpoints, parameters, and responses.
Usage of Nodemon for hot reload
Examples:
- Authorization with Google Access Token:
cURL
curl -X GET \
-H "Authorization: Bearer <access_token>" \
"http://localhost:9090/api/v1/auth"
# Debug mode:
curl -X GET \
-H "Authorization: dbname test" \
"http://localhost:9090/api/v1/auth"
- Create entry 1 (better uuid) under the "test" entity type:
cURL
curl -X POST \
-H "Authorization: Bearer <access_token>" \
-H "Content-Type: application/json" \
-d '{ "id": "1", "value": "value" }' \
"http://localhost:9090/api/v1/store/test"
# Debug mode:
curl -X POST \
-H "Authorization: dbname test" \
-H "Content-Type: application/json" \
-d '{ "id": "1", "value": "value" }' \
"http://localhost:9090/api/v1/store/test"
- Fetch entries:
cURL
curl -X GET \
-H "Authorization: Bearer <access_token>" \
"http://localhost:9090/api/v1/store/test"
# Debug mode:
curl -X GET \
-H "Authorization: dbname test" \
"http://localhost:9090/api/v1/store/test"
- Fetch entry 1:
cURL
curl -X GET \
-H "Authorization: Bearer <access_token>" \
"http://localhost:9090/api/v1/store/test/1"
# Debug mode
curl -X GET \
-H "Authorization: dbname test" \
"http://localhost:9090/api/v1/store/test/1"
- Delete entry 1:
cURL
curl -X DELETE \
-H "Authorization: Bearer <access_token>" \
"http://localhost:9090/api/v1/store/test/1"
# Debug mode
curl -X DELETE \
-H "Authorization: dbname test" \
"http://localhost:9090/api/v1/store/test/1"
Contributing:
Contributions to the project are welcome! Fork the repository, implement your changes, and submit a pull request.
License:
This project is licensed under the MIT license.
Resources:
- LevelDB: https://github.com/google/leveldb
- Node.js: https://nodejs.org/en
- Express.js: https://expressjs.com/
- Nodemon: https://github.com/remy/nodemon
- Google API Client Library for JavaScript: https://developers.google.com/api-client-library
Backup strategies
refer to: https://wiki.lyrasis.org/display/FEDORA46/Backup+and+Restore#BackupandRestore-FilesystemBackup Notes:
- This project is an example of using the Google API for authentication and LevelDB for data storage.
- The API can be easily modified to meet your specific needs.
- Please read the complete API documentation before using it.
I hope this project is useful to you!
Marco Aurélio Zoqui