Creating contracts between React front-end and C# back-end?

443 views Asked by At

I consider myself to be pretty well-versed in C#, but with React / Typescript I'm a relative beginner. One thing which I liked about pure C# projects is that my front-end and back-end can both be based off of the same object model, which means when I make an API call to the back-end, I can be sure that the object I'm passing from the front-end corresponds to the object I'm expecting to receive on the back-end.

Does something like this exist with React / Typescript? The project I'm working with, as-written, has an ApiModel.ts file (which is ostensibly auto-generated) that contains the models for the objects I'm passing - but to me, this feels like a weakly-typed setup. Other than a friendly warning message at the top of the file, there is nothing preventing me from modifying the ApiModel.ts file to add properties that are not present on the receiving end (which, presumably, would either cause an error or be handled internally).

Basically - tl;dr, is there any way for me to validate, at compile time, that the API model on the React side properly matches the API model on the C# side?

0

There are 0 answers