You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working on a library to simplify the interface between back-end and front-end in full-stack Typescript projects (eg. Nestjs API and Angular app).
A common practice to ensure consistency between back-end and front-end is to do the following:
Use decorators in the backend code (eg. from @nestjs/swagger)
Generate an OpenAPI spec
From this spec, generate a client library that can be used in the front-end project (eg from ng-openapi-gen)
What if we could skip the code generation step, reduce the amount of decorators in the back-end code, without losing the benefit of type-safety and request validation?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm working on a library to simplify the interface between back-end and front-end in full-stack Typescript projects (eg. Nestjs API and Angular app).
A common practice to ensure consistency between back-end and front-end is to do the following:
Use decorators in the backend code (eg. from @nestjs/swagger)
Generate an OpenAPI spec
From this spec, generate a client library that can be used in the front-end project (eg from ng-openapi-gen)
What if we could skip the code generation step, reduce the amount of decorators in the back-end code, without losing the benefit of type-safety and request validation?
Here is the approach I am taking:
From there, you get 3-for-1:
Type-safe HTTP client for the front-end
Type-safe controller interfaces for the backend (in particular for Nestjs, but it could work for other frameworks)
Generated OpenAPI spec (using zod-to-json-schema)
Here is a gist with a full example to give you an idea.
Beta Was this translation helpful? Give feedback.
All reactions