You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+23-7Lines changed: 23 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -4,9 +4,9 @@
4
4
5
5
## Introduction
6
6
7
-
**nestjs-endpoints** is a tool for easily and succinctly writing HTTP APIs with NestJS inspired by the [REPR pattern](https://www.apitemplatepack.com/docs/introduction/repr-pattern/), the [Fast Endpoints](https://fast-endpoints.com/) .NET library, [tRPC](https://trpc.io/), and Next.js' file-based routing.
7
+
**nestjs-endpoints** is a lightweight tool for writing clean and succinct HTTP APIs with NestJS that encourages the [REPR](https://www.apitemplatepack.com/docs/introduction/repr-pattern/) design pattern, code colocation, and the Single Responsibility Principle.
8
8
9
-
It features [zod](https://zod.dev/)input and output validation, comprehensive type-inference, and `@nestjs/swagger` + [nestjs-zod](https://github.com/BenLorantfy/nestjs-zod) to optionally automatically generate an OpenAPI spec file which can be used to then generate client SDKs using something like [orval](https://orval.dev/).
9
+
It's inspired by the [Fast Endpoints](https://fast-endpoints.com/).NET library, [tRPC](https://trpc.io/), and Next.js' file-based routing.
10
10
11
11
An endpoint can be as simple as this:
12
12
@@ -28,9 +28,10 @@ Hello, World!%
28
28
-**Easy setup:** Automatically scans your entire project for endpoint files and loads them.
29
29
-**File-based routing:** Each endpoint's HTTP path is based on their path on disk.
30
30
-**User-Friendly API:** Supports both basic and advanced per-endpoint configuration.
31
-
-**Fully typed:** Compile and run-time validation of input and output values using Zod schemas.
31
+
-**Schema validation:** Compile and run-time validation of input and output values using Zod schemas.
32
32
-**HTTP adapter agnostic:** Works with both Express and Fastify NestJS applications.
33
33
-**Stable:** Produces regular **NestJS Controllers** under the hood.
34
+
-**Client SDK codegen:** Annotates endpoints using `@nestjs/swagger` and [nestjs-zod](https://github.com/BenLorantfy/nestjs-zod) internally to output an OpenAPI document which [orval](https://orval.dev/) can use to generate a client library.
34
35
35
36
## Getting Started
36
37
@@ -150,9 +151,13 @@ null%
150
151
151
152
## File-based routing
152
153
153
-
HTTP paths for endpoints are determined by looking at the file's absolute path on disk,
154
-
stripping `rootDirectory`, then removing any path segments that start with an underscore (`_`).
155
-
Filenames must either end in `.endpoint.ts` or be `endpoint.ts` (`js`, `cjs`, `mjs`, `mts` are also supported).
154
+
HTTP paths for endpoints are derived by the file's path on disk:
155
+
156
+
-`rootDirectory` is removed from the start
157
+
- Path segments that begin with an underscore (`_`) are removed
158
+
- Filenames must either end in `.endpoint.ts` or be `endpoint.ts`
159
+
-`js`, `cjs`, `mjs`, `mts` are also supported.
160
+
- Route parameters are **not** suported (`user/:userId`)
156
161
157
162
Examples (assume `rootDirectory` is `./endpoints`):
158
163
@@ -289,7 +294,7 @@ To call this endpoint:
289
294
## OpenAPI, Codegen setup (optional)
290
295
291
296
It's a common practice to automatically generate a client SDK for your API that
292
-
you can use in other backend or frontend projects and have the benefit of full-stack type-safety. tRPC and similar libraries make this easy for you.
297
+
you can use in other backend or frontend projects and have the benefit of full-stack type-safety. tRPC and similar libraries have been written to facilitate this.
293
298
294
299
We can achieve the same here in two steps. We first build an OpenAPI document, then use that document's
295
300
output with [orval](https://orval.dev/):
@@ -311,3 +316,14 @@ async function bootstrap() {
311
316
awaitapp.listen(3000);
312
317
}
313
318
```
319
+
320
+
And then you could have something like this available:
Have a look at [this](https://github.com/rhyek/nestjs-endpoints/tree/main/packages/test-endpoints-module/test-app-express-cjs) test project to see how you might configure orval to generate an axios-based client and [here](https://github.com/rhyek/nestjs-endpoints/tree/main/packages/test-endpoints-module/test-app-express-cjs/test/client.e2e-spec.ts) to understand how you would use it.
0 commit comments