Is it possible to have multiple IReturn<>
on a request DTO?
For example following route:
[Route("/api/whatever", "GET,POST,PUT,DELETE")]
public class WhateverRequest : IReturn<bool>, IReturn<List<Whatever>>
{
public string WhateverId { get; set; }
}
Depending on the request method I want to have another IReturn
.
Post-Put-Delete Request should only return a acknowledge if the request was successful:
IReturn<bool>
but on a GET request I want to have a:
IReturn<List<Whatever>>
It would also be good if there is a way to reflect this in Swagger Api/ Metadata Page.
Currently only the first IReturn
is shown.
Is this possible or would it be better to create a route for each different IReturn
?
You definitely want to be creating different routes to handle the multiple return types. Only one
IReturn<T>
orIReturnVoid
is expected, or consuming clients wouldn't know how to type the returned data correctly.I presume you are returning
true
from these methods to show they completed successfully. Do the methods ever returnfalse
when something goes wrong, or is an exception thrown instead? If you are only throwing exception in the method, and never returning false then instead of returningbool
consider usingvoid
methods withIReturnVoid
. The request is therefore successful if it doesn't throw an exception.