I am creating a .net core api. For now it works well, but I would like to provide in the answers more useful information so that the customer can directly consume said information and not find a correct way to do it.
I have a generic driver that returns for now a vector with three objects with the information of the genres that are in the database:
[HttpGet]
public IEnumerable<Gender> GetAll()
{
List<Gender> GenderModel = new List<Gender>();
genderService.GetGender().ToList().ForEach(u => {
Gender genero = new Gender
(
u.Id,
u.Name
);
GenderModel.Add(gender);
});
return GenderModel.ToList();
}
The answer is as follows:
[
{
"id": 1,
"value": "Masculino"
},
{
"id": 2,
"value": "Femenino"
},
{
"id": 3,
"value": "Otros"
}
]
however, I would like the answer to have this form:
{
"results": [
{
"id": 0,
"value: "Otro"
},
{
"id": 1,
"value": "Masculino"
},
{
"id": 2,
"value": "Femenino"
}
],
"info": {
"results": 3,
"version": "1.0"
}
}
Obviously, any other information you want to add either as another JSON object or within the info object would also have to be sent. My problem is how to compose that answer. Another thing that is not quite clear is, the response from the .net core webapi is in vector format with objects inside, and usually all the apis I worked with were a response in JSON with other JSON objects inside , I have no problem working with this format in the front-end but I came to doubt.