NpgsqlRest 2.15.0
dotnet add package NpgsqlRest --version 2.15.0
NuGet\Install-Package NpgsqlRest -Version 2.15.0
<PackageReference Include="NpgsqlRest" Version="2.15.0" />
paket add NpgsqlRest --version 2.15.0
#r "nuget: NpgsqlRest, 2.15.0"
// Install NpgsqlRest as a Cake Addin #addin nuget:?package=NpgsqlRest&version=2.15.0 // Install NpgsqlRest as a Cake Tool #tool nuget:?package=NpgsqlRest&version=2.15.0
NpgsqlRest
Automatic REST API for PostgreSQL Databases implemented as AOT-Ready .NET8 Middleware
If you have a PostgreSQL database - NpgsqlRest can create blazing fast REST API automatically and write client code for your project.
Features:
- Nuget package for .NET that creates discoverable REST API automatically from PostgreSQL database.
- High Performance. See Performances Benchmarks.
- Modular Design with a Plug-in System. Create API for functions and procedure, create CRUD endpoints for your tables, create HTTP files, and Typescript client code.
- AOT-Ready. Ahead-of-time compiled to the native code. No dependencies, native executable, it just runs and it's very fast.
- Customizable. Configure endpoints with comment annotations. You can easily configure any endpoint by adding comment annotation labels to PostgreSQL Comments.
- Standalone Executable Web Client. Download the executable and run it. No installation required. See Releases.
Quick Example
1) Your PostgreSQL Function
create function hello_world()
returns text
language sql
as $$
select 'Hello World'
$$;
2) .NET8 AOT-Ready Web App
var builder = WebApplication.CreateSlimBuilder(args);
var app = builder.Build();
var connectionStr = "Host=localhost;Port=5432;Database=my_db;Username=postgres;Password=postgres";
app.UseNpgsqlRest(new(connectionStr));
app.Run();
3) Auto-Generated HTTP File
@host=http://localhost:5000
// function public.hello_world()
// returns text
POST {{host}}/api/hello-world/
4) Auto-Generated Typescript Client Module
const _baseUrl = "http://localhost:5000";
/**
* function public.get_latest_customer()
* returns customers
*
* @remarks
* GET /api/get-latest-customer
*
* @see FUNCTION public.get_latest_customer
*/
export async function getHelloWorld() : Promise<string> {
const response = await fetch(_baseUrl + "/api/hello-world", {
method: "GET",
headers: { "Content-Type": "application/json" },
});
return await response.text() as string;
}
5) Endpoint Response
HTTP/1.1 200 OK
Connection: close
Content-Type: text/plain
Date: Tue, 09 Jan 2024 14:25:26 GMT
Server: Kestrel
Transfer-Encoding: chunked
Hello World
Comment Annotations
Configure individual endpoints with powerful and simple routine comment annotations. You can use any PostgreSQL administration tool or a simple script:
Function:
create function hello_world_html()
language sql
as
$$
select '<div>Hello World</div>';
$$
comment on function hello_world_html() is '
HTTP GET /hello
Content-Type: text/html';
Will have content type text/html
as visible in comment annotation:
Connection: close
Content-Type: text/html
Date: Thu, 18 Jan 2024 11:00:39 GMT
Server: Kestrel
Transfer-Encoding: chunked
<div>Hello World</div>
Getting Started
Using Library
Library Installation
Install the package from NuGet by using any of the available methods:
dotnet add package NpgsqlRest --version 2.13.1
NuGet\Install-Package NpgsqlRest -version 2.13.1
<PackageReference Include="NpgsqlRest" Version="2.13.1" />
Library First Use
Your application builder code:
var app = builder.Build();
app.UseNpgsqlRest(new("Host=localhost;Port=5432;Database=my_db;Username=postgres;Password=postgres"));
app.Run();
For all available build options, see the options documentation.
Library Dependencies
- net9.0
- Microsoft.NET.Sdk.Web 9.0
- Npgsql 8.0.5
- PostgreSQL >= 13
Note: PostgreSQL 13 minimal version is required to run the initial query to get the list of functions. The source code of this query can be found here. For versions prior to version 13, this query can be replaced with a custom query that can run on older versions.
Contributing
Contributions from the community are welcomed. Please make a pull request with a description if you wish to contribute.
License
This project is licensed under the terms of the MIT license.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. |
-
net9.0
- Npgsql (>= 9.0.2)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on NpgsqlRest:
Package | Downloads |
---|---|
NpgsqlRest.TsClient
Automatic Typescript Client Code Generation for NpgsqlRest |
|
NpgsqlRest.CrudSource
CRUD Source for NpgsqlRest |
|
NpgsqlRest.HttpFiles
Automatic HTTP Files Generation for NpgsqlRest |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.15.0 | 87 | 12/21/2024 |
2.14.0 | 120 | 11/25/2024 |
2.13.1 | 93 | 11/23/2024 |
2.13.0 | 113 | 11/17/2024 |
2.12.1 | 105 | 11/6/2024 |
2.12.0 | 86 | 10/30/2024 |
2.11.0 | 131 | 9/3/2024 |
2.10.0 | 136 | 8/23/2024 |
2.9.0 | 72 | 8/2/2024 |
2.8.5 | 119 | 6/25/2024 |
2.8.4 | 115 | 6/22/2024 |
2.8.3 | 115 | 6/11/2024 |
2.8.2 | 117 | 6/9/2024 |
2.8.1 | 97 | 5/10/2024 |
2.8.0 | 99 | 5/2/2024 |
2.7.1 | 118 | 4/30/2024 |
2.7.0 | 132 | 4/17/2024 |
2.6.1 | 126 | 4/16/2024 |
2.6.0 | 123 | 4/16/2024 |
2.5.0 | 127 | 4/15/2024 |
2.4.2 | 143 | 4/14/2024 |
2.4.1 | 119 | 4/12/2024 |
2.4.0 | 188 | 4/8/2024 |
2.3.1 | 119 | 4/5/2024 |
2.3.0 | 150 | 4/4/2024 |
2.2.0 | 110 | 4/2/2024 |
2.1.0 | 128 | 3/29/2024 |
2.0.0 | 145 | 3/26/2024 |
1.6.3 | 121 | 2/19/2024 |
1.6.2 | 135 | 2/3/2024 |
1.6.1 | 120 | 2/2/2024 |
1.6.0 | 114 | 1/28/2024 |
1.5.1 | 106 | 1/27/2024 |
1.5.0 | 114 | 1/27/2024 |
1.4.0 | 111 | 1/26/2024 |
1.3.0 | 120 | 1/23/2024 |
1.2.0 | 126 | 1/22/2024 |
1.1.0 | 126 | 1/19/2024 |
1.0.0 | 132 | 1/18/2024 |
0.0.9 | 105 | 1/18/2024 |