GST.Library.API.REST
2.0.0
See the version list below for details.
dotnet add package GST.Library.API.REST --version 2.0.0
NuGet\Install-Package GST.Library.API.REST -Version 2.0.0
<PackageReference Include="GST.Library.API.REST" Version="2.0.0" />
paket add GST.Library.API.REST --version 2.0.0
#r "nuget: GST.Library.API.REST, 2.0.0"
// Install GST.Library.API.REST as a Cake Addin #addin nuget:?package=GST.Library.API.REST&version=2.0.0 // Install GST.Library.API.REST as a Cake Tool #tool nuget:?package=GST.Library.API.REST&version=2.0.0
GST Library API REST
Helper for building nice REST API
Install
Like all Nuget package: Install-Package GST.Library.API.REST
Model State validation
Base on Filip W's work.
This helper ensure that the Data Transfer Object (DTO) (also called "View Model"), is valid and not null.
If the model is null or invalid an HTTP response 400 within errors for each faulted property.
How to use it :
using GST.Library.API.REST.Annotations;
namespace My.API.Controllers
{
[Route("api/some")]
public class SomeController : Controller
{
[HttpPost]
[ModelStateValidation]
public IActionResult Post([FromBody] SomeInputViewModel scope)
{
return new OkObjectResult("Well Done !");
}
}
}
Pagination
Because pagination is something useful but redundant, here is a little help.
This helper store pagination data in the Header of the HTTP request.
You can find four data :
- int CurrentPage: The current page to show
- int ItemsPerPage: The number of items to show per page
- int TotalItems: The total number of items in the object
- int TotalPages: The total number of page to show all items of the object
How to use it :
using GST.Library.API.REST.Pagination;
namespace My.API.Controllers
{
[Route("api/some")]
public class SomeController : Controller
{
private int defaultFirstPage = 1;
private int defaultItemPerPage = 10;
[HttpGet]
public IActionResult Get([FromQuery]int? page, [FromQuery]int? limit)
{
// Do something nice
List<Object> objList = new List<Object>();
int currentPage = page == null || page < defaultFirstPage ? defaultFirstPage : (int)page;
int currentItemPerPage = limit == null || limit < defaultItemPerPage ? defaultItemPerPage : (int)limit;
int totalItem = objList.count();
int totalPages = (int)Math.Ceiling((double)totalItem / currentItemPerPage);
Response.AddPagination(currentPage, currentItemPerPage, totalItem, totalPages);
return new OkObjectResult(/* Lot of paginated object */);
}
}
}
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. |
.NET Core | netcoreapp2.0 is compatible. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
-
.NETCoreApp 2.0
- Microsoft.AspNetCore.Http (>= 2.0.0)
- Microsoft.AspNetCore.Mvc (>= 2.0.0)
- Newtonsoft.Json (>= 10.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.