I am very delighted to see that AutoWrapper now reached 21k downloads and 204 stars today! Woot! Big thanks to everyone who have supported it! I truly appreciate it. :)
Today, AutoWrapper 4.2.0 has been released with newly features added based on community feedback. Here are the newly features added:
[FIX]
FixStatus304NotModified
andStatus204NoContent
validation check. This addresses issue #46.[FIX]
Fix Content-Type response header value when[AutoWrapIgnore]
attribute is set. This addresses issue #55[NEW]
AddedIgnoreWrapForOkRequests
Attribute.[NEW]
HideIsError
attribute in the response for successful requests.[NEW]
Set defaultJSON
formatting toIndented
.[RFT]
Code Cleanup and Refactoring.
Samples
The default successful response output now removes the isError
attribute like:
{
"message": "GET Request successful.",
"result": {
"id": 1,
"firstName": "Vianne Maverich",
"lastName": "Durano"
}
}
If you want to completely ignore wrapping the response for successful requests to just output directly the data, you simply set the IgnoreWrapForOkRequests
to true
like in the following:
app.UseApiResponseAndExceptionWrapper(new AutoWrapperOptions {
IgnoreWrapForOkRequests = true,
});
You can use the [AutoWrapIgnore]
attribute as well to omit certain endpoints that you don't want to be wrapped. For example, if you want to return a file or raw text other than JSON
, you can simply do:
[HttpGet("getfile")]
[AutoWrapIgnore]
public FileStreamResult GetFile2()
{
var filePath = $"{Environment.CurrentDirectory}/Folder/Sample.txt";
using var file = System.IO.File.OpenRead(filePath);
var provider = new FileExtensionContentTypeProvider();
var fileInfo = new System.IO.FileInfo(filePath);
var memi = provider.Mappings[fileInfo.Extension];
return File(file, memi, fileInfo.Name);
}
[HttpGet("getfile2")]
[AutoWrapIgnore]
public FileStreamResult GetFile()
{
var path = $"{Environment.CurrentDirectory}/Folder/Sample.txt";
var stream = System.IO.File.OpenRead(path);
return new FileStreamResult(stream, "application/octet-stream");
}
[HttpGet("getexcel")]
[AutoWrapIgnore]
public IActionResult GetExcel()
{
var path = $"{Environment.CurrentDirectory}/sample.xlsx";
var stream = System.IO.File.OpenRead(path);
byte[] fileBytes = System.IO.File.ReadAllBytes(path);
return new FileContentResult(fileBytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
}
[HttpGet("getpdf")]
[AutoWrapIgnore]
public IActionResult GetPdf()
{
var path = $"{Environment.CurrentDirectory}/sample.pdf";
byte[] fileBytes = System.IO.File.ReadAllBytes(path);
return new FileContentResult(fileBytes, "application/pdf");
}
[HttpGet("getpdf2")]
[AutoWrapIgnore]
public IActionResult GetPdf2()
{
var path = $"{Environment.CurrentDirectory}/sample.pdf";
var stream = new FileStream(path, FileMode.Open);
return new FileStreamResult(stream, "application/pdf");
}
[HttpGet("getstring")]
[AutoWrapIgnore]
public ContentResult GetString()
{
return Content("Hello");
}
That's it!
Feel free to request an issue on github if you find bugs or request a new feature. Your valuable feedback is much appreciated to better improve this project. If you find this useful, please give it a star or be a sponsor to show your support on this project!