From 784e229de8988f10435972a08e985a4bcd758794 Mon Sep 17 00:00:00 2001 From: Henri Date: Sat, 23 Nov 2024 10:38:35 +0100 Subject: [PATCH 1/3] Add comparison with tRPC to README (#2180) Following discussion in https://github.com/RobinTail/express-zod-api/discussions/2178 --- README.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/README.md b/README.md index e4f329ef9..de15c2a9a 100644 --- a/README.md +++ b/README.md @@ -1413,6 +1413,37 @@ endpointsFactory.build({ }); ``` +# Comparison with other projects + +## tRPC + +[tRPC](https://trpc.io/) has a lot of goal and design similarities with express-zod-api: you can describe your type-safe API using zod and access it from a frontend client. + +The main difference between the two frameworks is that while they provide almost the same feature set, express-zod-api keeps compatiblity with REST and provides out-of-the box OpenAPI schema generation. + + +Design / DX comparison: + +| tRPC | express-zod-api | Comment | +| ------------- | ------------- | ------------ | +| Custom HTTP protocol | :+1: Regular REST | express-zod-api is great not only for greenfield projects but also for existing ones | +| Works mainly with mono-repo | :+1: Works as well with mono-repo and multi-repo | See https://github.com/trpc/trpc/discussions/1860 | +| Third-party REST and OpenAPI compatiblity | :+1: Out-of-the box | [trpc-openapi](https://github.com/jlalmes/trpc-openapi) does not seem to be maintained anymore | +| :+1: Automatic rich data serialization/deserialization with superjson | Depends on your client generator | | + + +Here is a mapping of concepts between the two projects for people that would like to migrate: + +| tRPC | express-zod-api | Comment | +| ------------- | ------------- | ------------ | +| router | routing | | +| publicProcedure | defaultEndpointsFactory | | +| Middleware `.use()` | Middleware `.addMiddleware()` | Both can be chained while retaining type-safety | +| Procedure | Endpoint | | +| Context | N/A | A middleware can be used instead | +| onError | ResultHandler | | + + # Your input to my output If you have a question or idea, or you found a bug, or vulnerability, or security issue, or want to make a PR: From 62ff63d5dc7ea7a04d2fe44657b07d8c5799531b Mon Sep 17 00:00:00 2001 From: Robin Tail Date: Sat, 23 Nov 2024 10:40:05 +0100 Subject: [PATCH 2/3] Applying mdfix. --- README.md | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index de15c2a9a..d85b62f64 100644 --- a/README.md +++ b/README.md @@ -1421,28 +1421,25 @@ endpointsFactory.build({ The main difference between the two frameworks is that while they provide almost the same feature set, express-zod-api keeps compatiblity with REST and provides out-of-the box OpenAPI schema generation. - Design / DX comparison: -| tRPC | express-zod-api | Comment | -| ------------- | ------------- | ------------ | -| Custom HTTP protocol | :+1: Regular REST | express-zod-api is great not only for greenfield projects but also for existing ones | -| Works mainly with mono-repo | :+1: Works as well with mono-repo and multi-repo | See https://github.com/trpc/trpc/discussions/1860 | -| Third-party REST and OpenAPI compatiblity | :+1: Out-of-the box | [trpc-openapi](https://github.com/jlalmes/trpc-openapi) does not seem to be maintained anymore | -| :+1: Automatic rich data serialization/deserialization with superjson | Depends on your client generator | | - +| tRPC | express-zod-api | Comment | +| --------------------------------------------------------------------- | ------------------------------------------------ | ---------------------------------------------------------------------------------------------- | +| Custom HTTP protocol | :+1: Regular REST | express-zod-api is great not only for greenfield projects but also for existing ones | +| Works mainly with mono-repo | :+1: Works as well with mono-repo and multi-repo | See https://github.com/trpc/trpc/discussions/1860 | +| Third-party REST and OpenAPI compatiblity | :+1: Out-of-the box | [trpc-openapi](https://github.com/jlalmes/trpc-openapi) does not seem to be maintained anymore | +| :+1: Automatic rich data serialization/deserialization with superjson | Depends on your client generator | | Here is a mapping of concepts between the two projects for people that would like to migrate: -| tRPC | express-zod-api | Comment | -| ------------- | ------------- | ------------ | -| router | routing | | -| publicProcedure | defaultEndpointsFactory | | -| Middleware `.use()` | Middleware `.addMiddleware()` | Both can be chained while retaining type-safety | -| Procedure | Endpoint | | -| Context | N/A | A middleware can be used instead | -| onError | ResultHandler | | - +| tRPC | express-zod-api | Comment | +| ------------------- | ----------------------------- | ----------------------------------------------- | +| router | routing | | +| publicProcedure | defaultEndpointsFactory | | +| Middleware `.use()` | Middleware `.addMiddleware()` | Both can be chained while retaining type-safety | +| Procedure | Endpoint | | +| Context | N/A | A middleware can be used instead | +| onError | ResultHandler | | # Your input to my output From e39a50ded3e9be698cefdff3c04c2b7471ae355f Mon Sep 17 00:00:00 2001 From: Robin Tail Date: Sat, 23 Nov 2024 10:58:54 +0100 Subject: [PATCH 3/3] Changing wide table to a vertical yaml for comparison. --- README.md | 59 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index d85b62f64..7666ae53f 100644 --- a/README.md +++ b/README.md @@ -1417,29 +1417,42 @@ endpointsFactory.build({ ## tRPC -[tRPC](https://trpc.io/) has a lot of goal and design similarities with express-zod-api: you can describe your type-safe API using zod and access it from a frontend client. - -The main difference between the two frameworks is that while they provide almost the same feature set, express-zod-api keeps compatiblity with REST and provides out-of-the box OpenAPI schema generation. - -Design / DX comparison: - -| tRPC | express-zod-api | Comment | -| --------------------------------------------------------------------- | ------------------------------------------------ | ---------------------------------------------------------------------------------------------- | -| Custom HTTP protocol | :+1: Regular REST | express-zod-api is great not only for greenfield projects but also for existing ones | -| Works mainly with mono-repo | :+1: Works as well with mono-repo and multi-repo | See https://github.com/trpc/trpc/discussions/1860 | -| Third-party REST and OpenAPI compatiblity | :+1: Out-of-the box | [trpc-openapi](https://github.com/jlalmes/trpc-openapi) does not seem to be maintained anymore | -| :+1: Automatic rich data serialization/deserialization with superjson | Depends on your client generator | | - -Here is a mapping of concepts between the two projects for people that would like to migrate: - -| tRPC | express-zod-api | Comment | -| ------------------- | ----------------------------- | ----------------------------------------------- | -| router | routing | | -| publicProcedure | defaultEndpointsFactory | | -| Middleware `.use()` | Middleware `.addMiddleware()` | Both can be chained while retaining type-safety | -| Procedure | Endpoint | | -| Context | N/A | A middleware can be used instead | -| onError | ResultHandler | | +[tRPC](https://trpc.io/) has a lot of goal and design similarities with Express Zod API: you can describe your +type-safe API using zod and access it from a frontend client. The main difference between the two frameworks is that +Express Zod API keeps compatiblity with REST and provides out-of-the box OpenAPI schema generation. + +```yaml +design: + Protocol: + tRPC: custom + express-zod-api: REST + comment: Express Zod API is great not only for greenfield projects but also for existing ones + Serialization: + tRPC: https://www.npmjs.com/package/superjson + express-zod-api: JSON + comment: JSON parser can be customized in config + Repo: + tRPC: mainly for mono-repo + comment: https://github.com/trpc/trpc/discussions/1860 + express-zod-api: mono-repo and multi-repo + OpenAPI: + tRPC: Third-party + comment: https://github.com/jlalmes/trpc-openapi + express-zod-api: Out-of-the box +entities: + - tRPC: router + express-zod-api: routing + - tRPC: publicProcedure + express-zod-api: EndpointsFactory + - tRPC: .use() + express-zod-api: .addMiddleware() + comment: or .use() for native express middlewares + - tRPC: Context + express-zod-api: options + comment: Middleware can be used to provide options + - tRPC: onError + express-zod-api: ResultHandler +``` # Your input to my output