I have a REST API uploadFeed that uploads the user feed based on feedType (string value taken input as part of the request body) . Different feedtype provides a different pojo model in the request body altogether.
For e.g If the feedType is lets say "TYPE1", then the API's request-body should look like the following:
{
"feedType":"TYPE1",
"inputModel": {
"a": "somevalue"
"b" : "somevalue",
"c" : "somevalue",
}
}
if the feedType is lets say "TYPE2", then the API's request-body should look like the following:
{
"feedType":"TYPE2",
"inputModel": {
"x": "somevalue"
"y" : "somevalue",
"z" : "somevalue",
}
}
What would be best API Design for the uploadFeed API. I am thinking of having two possible solutions:
Solution Proposal-1: Have two different API endpoints.
API URI for feedType == Type1: /uploadFeed/feedType/{Type1}. Here the requestBody here shall be same as the one mentioned above for Type1
API URI for feedType == Type2: /uploadFeed/feedType/{Type2}. Here the requestBody here shall be same as the one mentioned above for Type2
Solution Proposal-2: Have one endpoint with both model present. For feedType as TYPE1, expected requestBody shall be
{
"feedType":"TYPE1",
"type1Model": {
"a": "somevalue"
"b" : "somevalue",
"c" : "somevalue",
},
"type2Model" : null
}
For feedType as TYPE2, expected requestBody shall be
{
"feedType":"TYPE1",
"type1Model" : null
"type2Model": {
"x": "somevalue"
"y" : "somevalue",
"z" : "somevalue",
},
}
Is there any other possible way. Please suggest the best solution possible (not necessarily out of these two).