I create app using C# RestApi as backend and React as frontend. I would like to ask you whether you inventory the use of backend models in the front.
In VS (C#) I can use F12 to detect reference. I have no idea how to do this in REST where JS does not need to recreate the class.
The backend developer may not be able to access the frontend code. Do you have any practice on how to record the use of the model on the REST/React so that the developer can quickly see if he can change the appearance of the backend model class.
CodePudding user response:
ok you should have to make Restapi in asp.net and make it open to use.On the front-end use the callapi method with base URL. Remember Base url is the url where your restApi are hosted. it looks like this
const response = await callApi(
'/Lab/SearchPendingLabResults',
'post',
this.state.saveModal
).then(res => {
this.setState({
LabData:res
})
})
} catch (error) {}
If you are using the post api then you should have to create a model in react js and pass this model into api payload .The model looks like this
this.state = {
providerid: null,
locationid: null,
patientname:'',
patientid:'',
fromDate: this.getTodayDate(),
toDate: this.getTodayDate(),
}
if you are using the GET api then you just need to use callapi method and base url of api to get the response
CodePudding user response:
Well, there is no strict connection between models defined in the backend and frontend in this case. The connection is just made when a client calls an endpoint on a server. The most common practice is to use DTO as returned data(Data Transfer Object) with all properties which you need on the front, not models. So on the frontend, you create the same class as DTO on the backend and you just use some libs to support the process of mapping like the automapper. In this case detection of using models needs to be found by URL.