Why do we need a typesafe REST API?
A typesafe REST API ensures data consistency, reduces errors, and enhances developer productivity by enforcing strict data type checks at compile time. It provides clear documentation, improves code maintainability, and facilitates seamless integration and scalability of services.Express
Our ExpressJS implementation is inspire from the Bullet-Proof NodeJS Guide. It supports:- Logging
- Dependency Injection
- Seperation using routes, services and interfaces.
- Out-of-the-box Open-API spec.
- Beautiful Reference page using Scaler.
TS-Rest
Using TS-Rest, we declare contracts to be the basis of the interaction between the client and the server. Everything is defined and typed using Zod Schema in the contracts. For example:Why not something like TRPC?
One of the biggest differences between tRPC and ts-rest is that tRPC defines your API implementation as the contract, for some use cases it is beneficial to have a separate contract to represent the API. TS-Rest offers a plethora of frontend wrappers likereact-query
or solid-query
but what if you want to consume the API on a micro-controller?
Well, do not worry, you can just consume it like a normal Rest API.
You will not get the typed definition this way but atleast you can consume it.