Easy-DB
Easy-DB is a lightweight, secure, and zero-boilerplate Rust library that instantly turns SQLite tables into a fully functional REST API. It comes with a built-in, type-safe client to streamline backend-frontend communication.
Features
- Zero Boilerplate: No need to define structs or extensive router configurations. Just define your SQL schema and go.
- Instant CRUD: Automatically generates GET, POST, PUT, and DELETE endpoints for every exposed table.
- Secure by Design:
- SQL Injection Protection: Uses parameterized queries (
?) for all data values. - Identifier Sanitization: Strictly validates table and column names to prevent identifier injection attacks.
- SQL Injection Protection: Uses parameterized queries (
- Built-in Client: Includes
EasyClientto handle HTTP requests without manual overhead. - Advanced Querying: Supports filtering and sorting via URL parameters out of the box.
- CORS Enabled: Ready for frontend integration (React, Vue, etc.).
Installation
Add this to your Cargo.toml:
[]
= "0.2.1"
= { = "1.0", = ["full"] }
= "1.0"
= "1.0"
Quick Start
Running Server and Client in a Single File
For testing or small applications, you can run the server in a background task and the client in the main thread using tokio::spawn. This allows you to run a complete system demo from a single file.
use ;
use json;
use Duration;
use sleep;
async
API Reference
Once the server is running, the following endpoints are automatically generated for every table you create:
| Method | Endpoint | Description | Body / Query Params |
|---|---|---|---|
| GET | /:table |
List records | ?col=val (filter), ?_sort=col&_order=desc |
| POST | /:table |
Create record | JSON Object of the columns |
| PUT | /:table/:id |
Update record | JSON Object of the columns to change |
| DELETE | /:table/:id |
Delete record | None |
Filtering & Sorting Example
To get users named "Alice", sorted by age descending:
GET /users?name=Alice&_sort=age&_order=desc
Security
Easy-DB takes security seriously. Unlike many basic dynamic API generators, it prevents Identifier Injection:
- Whitelisting: Table and column names are checked against a strict alphanumeric whitelist (
[a-zA-Z0-9_]). - Parameterized SQL: All values provided by the client are handled via prepared statements (
?placeholders), making standard SQL injection attacks impossible.
License
This project is licensed under the MIT License.