|
9 | 9 |
|
10 | 10 | > Transform your PostgreSQL database into a production-ready REST API server with automatic TypeScript code generation and end-to-end type safety. |
11 | 11 |
|
| 12 | +<p align="center"> |
| 13 | + <img src="clean.png" alt="NpgsqlRest Architecture" width="500"> |
| 14 | +</p> |
| 15 | + |
12 | 16 | **[Documentation](https://npgsqlrest.github.io/)** | **[Getting Started](https://npgsqlrest.github.io/getting-started/)** | **[Configuration Reference](https://npgsqlrest.github.io/config-reference/)** | **[Annotation Guide](https://npgsqlrest.github.io/comment-annotations/)** |
13 | 17 |
|
14 | 18 | ## Key Features |
15 | 19 |
|
16 | 20 | - **Instant API Generation** - Automatically creates REST endpoints from PostgreSQL functions, procedures, tables, and views |
17 | 21 | - **Declarative Configuration** - Configure endpoints directly in your database using comment annotations |
18 | | -- **TypeScript Code Generation** - Auto-generate type-safe frontend code with full static type checking |
| 22 | +- **Code Generation** - Auto-generate frontend TypeScript/JavaScript code and .http files for testing |
| 23 | +- **High Performance** - check out [benchmarks](https://npgsqlrest.github.io/blog/postgresql-rest-api-benchmark-2025.html) showing low latency and high throughput. Latest benchmark show that it is 6.1x faster than PostgREST at 100 concurrent users, |
19 | 24 | - **Native Executables** - AOT-compiled binaries with zero dependencies and instant startup |
20 | 25 | - **RESTful Path Parameters** - Define routes like `/products/{id}` with parameters extracted from URL paths |
21 | 26 | - **Reverse Proxy Endpoints** - Forward requests to upstream services with passthrough or transform modes |
22 | 27 | - **HTTP Custom Types** - Enable PostgreSQL functions to call external APIs via annotated composite types |
23 | 28 | - **Enterprise Ready** - Authentication, authorization, rate limiting, caching, SSE streaming, OpenAPI 3.0, and more |
24 | 29 |
|
25 | | -## Quick Start |
26 | | - |
27 | | -### 1. Annotate a PostgreSQL Function |
28 | | - |
29 | | -```sql |
30 | | -create function hello(_name text) |
31 | | -returns text |
32 | | -language sql as $$ |
33 | | -select 'Hello, ' || _name |
34 | | -$$; |
35 | | - |
36 | | -comment on function hello(text) is 'HTTP GET /hello'; |
37 | | -``` |
38 | | - |
39 | | -### 2. Configure Connection |
40 | | - |
41 | | -Create `appsettings.json`: |
42 | | - |
43 | | -```json |
44 | | -{ |
45 | | - "ConnectionStrings": { |
46 | | - "Default": "Host=localhost;Port=5432;Database=my_db;Username=postgres;Password=postgres" |
47 | | - } |
48 | | -} |
49 | | -``` |
| 30 | +## Clean Architecture Done Right |
50 | 31 |
|
51 | | -### 3. Run |
| 32 | +Clean Architecture tells us to keep business logic independent of frameworks, databases, and delivery mechanisms. In practice, this often means layers upon layers of abstractions, DTOs, mappers, and repositories - all trying to "protect" the domain from the database. |
52 | 33 |
|
53 | | -```bash |
54 | | -# Download from releases, or: |
55 | | -npm i npgsqlrest && npx npgsqlrest |
| 34 | +But what if the database *is* the best place for your business logic? |
56 | 35 |
|
57 | | -# Or with Docker: |
58 | | -docker run -p 8080:8080 -v ./appsettings.json:/app/appsettings.json vbilopav/npgsqlrest:latest |
59 | | -``` |
| 36 | +PostgreSQL is not just storage. It's a powerful computation engine with transactions, constraints, triggers, functions, and decades of optimization. NpgsqlRest flips the script: instead of abstracting away the database, it puts PostgreSQL at the center and generates everything else. |
60 | 37 |
|
61 | | -Your API is now live at `http://localhost:8080/hello?name=World` |
| 38 | +- **Schema as contract** - Your tables, views, and functions become REST endpoints. One source of truth, zero drift. |
| 39 | +- **SQL comments as config** - Routes, auth rules, caching - all declared where the logic lives. |
| 40 | +- **Types flow outward** - PostgreSQL types generate TypeScript clients automatically. No manual mappings. |
| 41 | +- **No middle tier** - No ORM impedance mismatch, no N+1 queries, no controller boilerplate. |
62 | 42 |
|
63 | | -## Installation Options |
| 43 | +## Installation |
64 | 44 |
|
65 | 45 | | Method | Command | |
66 | 46 | |--------|---------| |
|
0 commit comments