I want to send two different json response for the same API based on a flag.
I have a final response json as below for /api/v1/student/, which is created by fetching responses from few other REST apis.
{
"students": [{
"name": "string",
"courses": [{
"courseid": "string",
"coursename": "string"
}],
"studentId": "string",
"enrollments": [{
"key1": "string",
"key2": "string",
"key3": "string",
"curricular": [{
"date": "string",
"item1": "string",
"item2": "string",
"fees": "string",
"details": [{
"item1": "string",
"item2": "string"
}]
}]
}]
}]
}
Consider a scenario where I have to support this response and another similar response where the "details" block will change based on a flag.
Is creating two versions of api as /api/v1/student/ and /api/v2/student/ the only solution or there is other better approach(es)?
A follow up question for going with v2 approach: I am structuring the response as these model objects - Details, Curricular, Enrollment, Students
ex:
Students : {
Enrollment : {
Curricular: {
Details
}
}
}
and now since the nested block - Details is changing I will have to repeat all model classes and mark them as V2 and also duplicate the code for mapping the fields. Does that look right? Thanks for your help!