NpgsqlRest 0.0.9

There is a newer version of this package available.
See the version list below for details.
dotnet add package NpgsqlRest --version 0.0.9                
NuGet\Install-Package NpgsqlRest -Version 0.0.9                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NpgsqlRest" Version="0.0.9" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NpgsqlRest --version 0.0.9                
#r "nuget: NpgsqlRest, 0.0.9"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install NpgsqlRest as a Cake Addin
#addin nuget:?package=NpgsqlRest&version=0.0.9

// Install NpgsqlRest as a Cake Tool
#tool nuget:?package=NpgsqlRest&version=0.0.9                

NpgsqlRest

Automatic REST API for Any Postgres Database as NET8 Middleware

1) 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();
app.UseNpgsqlRest(new("Host=localhost;Port=5432;Database=my_db;Username=postgres;Password=postgres"));
app.Run();

3) Auto-Generated HTTP File (Optional)

@host=http://localhost:5000

// function public.hello_world()
// returns text
POST {{host}}/api/hello-world/

4) 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

Features

  • Automatic generation of REST endpoints from PostgreSQL functions.
  • Native AOT Ready.
  • Customization of endpoints with comment annotations.
  • Automatic HTTP files.
  • Interact seamlessly with NET8 backend and take advantage of NET8 features.

Automatic Generation of REST Endpoints

See the introductory example above.

Native AOT Ready

With the NET8 you can build into native code code (ahead-of-time (AOT) compilation).

NpgsqlRest is fully native AOT-ready and AOT-tested.

AOT builds have faster startup time, smaller memory footprints and don't require any .NET runtime installed.

Comment Annotations

Configure individual endpoints with powerful and simple routine comment annotations. You can use any PostgreSQL administration tool or a simple script:

create function hello_world_html() returns text language sql as 
$$
select '<div>Hello World</div>';
$$

comment on function hello_world_html() is '
Using comment annotations to configure this endpoint.
HTTP GET /hello
Content-Type: text/html';
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
      Request finished HTTP/1.1 GET http://localhost:5000/api/hello - 200 - text/html 29.7810ms
Connection: close
Content-Type: text/html
Date: Thu, 18 Jan 2024 11:00:39 GMT
Server: Kestrel
Transfer-Encoding: chunked

<div>Hello World</div>

Automatic HTTP Files

Create automatically HTTP file(s) with ready-made randomized test example calls.

NET8 backend

NpgsqlRest is implemented as a NET8 middleware component, which means that anything that is available in NET8 is also available to the NpgsqlRest REST endpoints. And that is, well, everything. From rate limiters to all kinds of authorization schemas, to name a few.

You can also interact with the NET8 calling code. Do you want to supply the username to all parameters named "user"? No problem, how about this:

var app = builder.Build();
app.UseNpgsqlRest(new(connectionString)
{
    ValidateParameters = p =>
    {
        if (p.Context.User.Identity?.IsAuthenticated == true && 
            string.Equals(p.ParamName, "user", StringComparison.OrdinalIgnoreCase))
        {
            p.Parameter.Value = p.Context.User.Identity.Name;
        }
    } 
});
app.Run();

Getting Started

Installation

  • .NET CLI:
dotnet add package NpgsqlRest
  • Package Manager:
NuGet\Install-Package Norm.net
  • Package Reference:
<PackageReference Include="NpgsqlRest" />
  • Script & Interactive:
#r "nuget: NpgsqlRest"

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, please consult a source code file, until proper documentation is built.

Dependencies

  • net8.0
  • Microsoft.NET.Sdk.Web 8.0
  • Npgsql 8.0.1

Contributing

We welcome contributions from the community. Please make a pull request if you whish to contribute.

License

This project is licensed under the terms of the MIT license.

Contact

If you have any questions or feedback, please feel free to contact us.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.12.1 76 11/6/2024
2.12.0 73 10/30/2024
2.11.0 121 9/3/2024
2.10.0 124 8/23/2024
2.9.0 59 8/2/2024
2.8.5 109 6/25/2024
2.8.4 103 6/22/2024
2.8.3 105 6/11/2024
2.8.2 107 6/9/2024
2.8.1 85 5/10/2024
2.8.0 89 5/2/2024
2.7.1 110 4/30/2024
2.7.0 124 4/17/2024
2.6.1 116 4/16/2024
2.6.0 113 4/16/2024
2.5.0 119 4/15/2024
2.4.2 133 4/14/2024
2.4.1 111 4/12/2024
2.4.0 180 4/8/2024
2.3.1 109 4/5/2024
2.3.0 142 4/4/2024
2.2.0 100 4/2/2024
2.1.0 120 3/29/2024
2.0.0 137 3/26/2024
1.6.3 113 2/19/2024
1.6.2 125 2/3/2024
1.6.1 112 2/2/2024
1.6.0 106 1/28/2024
1.5.1 96 1/27/2024
1.5.0 106 1/27/2024
1.4.0 103 1/26/2024
1.3.0 112 1/23/2024
1.2.0 116 1/22/2024
1.1.0 118 1/19/2024
1.0.0 119 1/18/2024
0.0.9 99 1/18/2024