KnowYourToolset.ApiComponents
1.0.1
See the version list below for details.
dotnet add package KnowYourToolset.ApiComponents --version 1.0.1
NuGet\Install-Package KnowYourToolset.ApiComponents -Version 1.0.1
<PackageReference Include="KnowYourToolset.ApiComponents" Version="1.0.1" />
<PackageVersion Include="KnowYourToolset.ApiComponents" Version="1.0.1" />
<PackageReference Include="KnowYourToolset.ApiComponents" />
paket add KnowYourToolset.ApiComponents --version 1.0.1
#r "nuget: KnowYourToolset.ApiComponents, 1.0.1"
#addin nuget:?package=KnowYourToolset.ApiComponents&version=1.0.1
#tool nuget:?package=KnowYourToolset.ApiComponents&version=1.0.1
KnowYourToolset.ApiComponents
Getting Started
The features in this ApiComponents
package are:
- ProblemDetails middleware that can be used by API projects and easily return a customizable
ProblemDetails
object* when errors (unhandled exceptions) occur
Using the ProblemDetails middleware
To use the middleware for exception handling, simply call the UseProblemDetailsHandler
extension method in the Configure
method in Startup.cs
.
You can call UseProblemDetailsHandler
with no parameters to use defaults, and it will return a base-level ProblemDetails
object
with a variety of its properties filled in whenever an unhandled exception occurs.
If you want to add some additional context to the ProblemDetails
response or use something
other than 500-InternalServerError
for the HTTP status, just use the AddResponseDetails
option
and provide a delegate method with your own logic (the CustomizeResponse
method
in the example below).
To do that, your Configure
method might end up looking something like this:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseProblemDetailsHandler(options => options.AddResponseDetails = CustomizeResponse);
//... more code here ...
}
private HttpStatusCode CustomizeResponse(HttpContext httpContext, Exception exception, ProblemDetails problemDetails)
{
if (exception is ApplicationException appEx)
{
problemDetails.Detail = appEx.Message;
return HttpStatusCode.BadRequest;
}
return HttpStatusCode.InternalServerError;
}
** Sample:** A sample API that uses this is the KnowYourToolset.BackEnd template in the KnowYourToolset.Templates
package.
You can create a project using this template if you want to experiment with it.
Contributing
This is meant to be very simple and minimalistic features that can support ASP.NET Core+ API projects.
Feel free to use this code as a starter for things you might want to do in the same direction for your projects, or if you feel that something belongs in here, use the following workflow:
- Fork the repo
- Create a branch
- Make your changes (and test them!) in the branch you created
- Commit your changes
- Submit a Pull Request
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Microsoft.AspNetCore.Mvc.Core (>= 2.2.5)
- Serilog (>= 2.10.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.2 | 614 | 8/12/2021 |
1.0.2-alpha.0.4 | 179 | 8/12/2021 |
1.0.2-alpha.0.3 | 177 | 8/12/2021 |
1.0.1 | 398 | 8/7/2021 |
1.0.1-alpha.0.1 | 236 | 8/7/2021 |
1.0.0 | 407 | 8/7/2021 |
0.0.0-alpha.0.3 | 281 | 8/7/2021 |
0.0.0-alpha.0.2 | 166 | 8/7/2021 |
0.0.0-alpha.0.1 | 190 | 8/6/2021 |