Add Results.Empty
See original GitHub issueBackground and Motivation
Sometimes you want to return a result that does not mutate the response in anyway. This happens when you have multiple branches in a route handle and one of them should be a noop. You are forced to return an IResult and we don’t have a built in result type that fills this role. Mvc has EmptyResult for this purpose.
Proposed API
namespace Microsoft.AspNetCore.Http
{
public static class Results
{
public static IResult Empty(); // This could also be a property
}
}
Usage Examples
app.MapGet("/{id}", (HttpContext context, string id) =>
{
var httpProcessor = GetTargetStream(id);
if (httpProcessor is null) return Results.NotFound();
await httpProcessor.ProcessAsync(context);
// Don't change what the httpProcessor did
return Results.Empty();
});
Alternative Designs
Force people to write their own.
Risks
None
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Add empty row to query results if no results found
The obvious way to achieve this is create a temp table, put the results into it, test for any rows in the temp...
Read more >Setting Empty Results Messages
Specifies the action or actions to display for the empty results in either a dropdown menu, a link, or a button, depending on...
Read more >how to display a 0 result instead an empty result
Solved: hi I use the search below and I would like to have a 0 results displayed when there is no events corresponding...
Read more >Creating empty (avoid creating an output at all) when ...
Context: When using an if-condition inside an array_foreach() function, for each element with empty output ( result_when_false ), a '' or NULL ......
Read more >Solved: Handling Empty Results
Solved: Hi I have a query which returns a list of issues in jason format which I then transform into a table and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
API review:
We’ll use properties instead. Here’s the approved API:
Yep