RestSQL is a .NET tool that effortlessly converts SQL queries defined in YAML into RESTful endpoints. With support for transactions and nested JSON output, it simplifies API development for multiple database providers. Set it up standalone or integrate it into your application as a library with minimal configuration.
RestSQL is a versatile .NET tool designed to transform SQL queries defined in YAML into fully functional REST endpoints. This project can be deployed as a standalone API or integrated as a library within existing applications. It supports transactions, delivers nested JSON output, and accommodates multiple database providers, making it a robust solution for web services.
RestSQL offers two primary usage options:
Quickly deploy a pre-built API project by configuring the appsettings.json:
{
"RestSQL": {
"ConfigFolder": "path/to/your/yaml/configs"
},
"Serilog": {
"MinimumLevel": {
"Default": "Information"
},
"WriteTo": [
{
"Name": "Console"
}
]
}
}
Run the API with:
cd src/RestSQL.Api
dotnet run
To integrate RestSQL into an existing ASP.NET Core project, simply add the library:
// Program.cs
builder.Services.AddRestSQL();
app.UseRestSQL("path/to/config/folder");
Configuration in RestSQL is handled via YAML files, including sections for database connections and API endpoint definitions:
Database Connections:
connections:
postgres1:
type: PostgreSQL
connectionString: "Host=localhost;Database=mydb;Username=user;Password=pass"
mysql1:
type: MySql
connectionString: "Server=localhost;Database=mydb;User=user;Password=pass"
Endpoint Configuration:
endpoints:
- path: /api/posts
method: GET
statusCode: 200
sqlQueries:
posts:
connectionName: blog
sql: >
select id post_id, title, description, creation_date, username
from posts;
outputStructure:
type: Object
isArray: true
queryName: posts
fields:
- { type: Long, name: id, columnName: post_id }
- { type: String, name: title, columnName: title }
GET /api/posts
Response:
[
{
"id": 1,
"title": "The Joys of Async/Await",
"description": "A deep dive into non-blocking operations in C#.",
"creationDate": "2025-10-25T15:03:04",
"username": "alice_codes",
"tags": ["C#", "Async"]
}
]
POST /api/posts
{
"title": "PostgreSQL vs MySQL",
"description": "A performance comparison",
"username": "bob_devs"
}
Response:
{
"id": 2,
"title": "PostgreSQL vs MySQL",
"description": "A performance comparison",
"username": "bob_devs",
"creationDate": "06/11/2025 10:30:41",
"tags": []
}
For more information and usage examples, refer to the development setup and further documentation in the project repository.
No comments yet.
Sign in to be the first to comment.