Skip to content

Commit 76f86a9

Browse files
committed
fix readme
1 parent 8f09a58 commit 76f86a9

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

README.md

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
## Introduction
66

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.
88

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.
1010

1111
An endpoint can be as simple as this:
1212

@@ -28,9 +28,10 @@ Hello, World!%
2828
- **Easy setup:** Automatically scans your entire project for endpoint files and loads them.
2929
- **File-based routing:** Each endpoint's HTTP path is based on their path on disk.
3030
- **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.
3232
- **HTTP adapter agnostic:** Works with both Express and Fastify NestJS applications.
3333
- **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.
3435

3536
## Getting Started
3637

@@ -150,9 +151,13 @@ null%
150151

151152
## File-based routing
152153

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`)
156161

157162
Examples (assume `rootDirectory` is `./endpoints`):
158163

@@ -289,7 +294,7 @@ To call this endpoint:
289294
## OpenAPI, Codegen setup (optional)
290295

291296
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.
293298

294299
We can achieve the same here in two steps. We first build an OpenAPI document, then use that document's
295300
output with [orval](https://orval.dev/):
@@ -311,3 +316,14 @@ async function bootstrap() {
311316
await app.listen(3000);
312317
}
313318
```
319+
320+
And then you could have something like this available:
321+
322+
```typescript
323+
const { id } = await userCreate({
324+
name: 'Tom',
325+
326+
});
327+
```
328+
329+
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

Comments
 (0)