GST.Library.API.REST 2.0.0

There is a newer version of this package available.
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                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GST.Library.API.REST" Version="2.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add GST.Library.API.REST --version 2.0.0                
#r "nuget: GST.Library.API.REST, 2.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
3.0.0 841 11/14/2019
2.2.2 1,154 1/21/2019
2.2.1 795 1/9/2019
2.1.1 1,397 6/1/2018
2.1.0 1,029 6/1/2018
2.0.0 1,103 10/26/2017
1.0.1 1,108 4/12/2017
1.0.0 1,068 4/6/2017