GST.Library.API.REST 2.0.0

API Rest Helper

There is a newer version of this package available.
See the version list below for details.
Install-Package GST.Library.API.REST -Version 2.0.0
dotnet add package GST.Library.API.REST --version 2.0.0
<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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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 */);
        }
    }
}

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 */);
        }
    }
}

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
2.2.2 426 1/21/2019
2.2.1 143 1/9/2019
2.1.1 556 6/1/2018
2.1.0 194 6/1/2018
2.0.0 295 10/26/2017
1.0.1 302 4/12/2017
1.0.0 258 4/6/2017