Skip to content

Commit

Permalink
Changing wide table to a vertical yaml for comparison.
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinTail committed Nov 23, 2024
1 parent 62ff63d commit e39a50d
Showing 1 changed file with 36 additions and 23 deletions.
59 changes: 36 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e39a50d

Please sign in to comment.