Reputation: 2701
I have an API controller with method that returns a IEnumerable. Method GetProjects returns List<(string, object)>
:
[HttpGet]
[Route("getProjects")]
public async Task<IEnumerable<(string, object)>> GetProjects(string departmentName)
{
var result = await dataService.GetProjects(departmentName);
return result.AsEnumerable();
}
Should the result be convert to IEnumerable
before returning it from API or can it be returning as Task<List<(string, object)>>
?
Recommendations from .NET guidelines are that List should be be returned from API:
dotnet standard design-guidelines guidelines-for-collections
What is a benefit of conversion List to IEnumerable in the above case? This is additional operation. Result in Angular service for IEnumerable and List looks the same. It looks like array in json.
Upvotes: 0
Views: 47