Conclusion

Congrats!! You have come this far. Lets try to summarize together what we have learnt in this series.

Data modelling and designing requirements

We learnt how to identify entities, and their different actions which are part of of our logic. We translated these entities to prisma models, and learnt how to perform database operations through prisma.

Schema driven development using ts-rest contracts

We derived a specification of all our different endpoints, and then we translated those into ts-rest contracts. We learnt how these contracts can be used both client side, and server side for an optimized developer experience using enhanced type-safety, and auto-complete provided by these contracts, and not to mention how effortlessly we get runtime data validation through Zod.

Controllers and middlewares

We went through the basic concepts of a web framework such as controllers, and middlewares. We talked about how controllers, and middlewares are basically just functions that get a request object as an input, apply some business logic on it, and then return a response to the client(or forward the request in case of middlewares). We also made a basic authentication middleware that was crucial for user identification, and security.

Moreover we experienced how ts-rest greatly improves the developer experience of writing controllers with its powerful typings.

Express integraion

After that, we used ts-rest/express to convert our controllers, middlewares and contracts to actual express endpoints.

We also talked about how the implementation of these controllers, and contracts are independent of any web framework, and we could have just as easily used another web framework with minimal changes to the code.

Swagger UI

In order to interact with, and test our API, we made a swagger ui. The process was pretty simple. We used ts-rest/open-api to generate an OpenAPI document, and then passed that document to swagger-ui-express. Voila! We have a full fledged UI catered to our API in the web.

Extras

We also looked at some other features provided by ts-rest such as API versioning using a path prefix in the contract, a custom client using axios, type inference utility helpers to infer the types of the request, and responses of any endpoints.

Personal note

ts-rest is still a very new project. Although it has been marked as production ready, use it with caution. The project seems to have a lot of potential, and it will be really interesting to see it evolve. Thank you for reading thus far 😃.