-
Notifications
You must be signed in to change notification settings - Fork 8
REST Controllers examples
Ushakov Michael edited this page Sep 18, 2025
·
17 revisions
This page contains examples of how to Create REST Controllers with Wissance.WebApiToolkit.
This controller class contains the following methods:
-
GET /api/[controller]/?[page={page}&size={size}&sort={sort}&order={order}]to get collection ofPagedDataDto<T> -
GET /api/[controller]/{id}to get one object byid
Consider we have to create the Book Controller with EntityFramework:
- Create a book entity and implement the
IModelIdentifiable<T>interface.
public class BookEntity : IModelIdentifiable<int>
{
public int Id {get; set;}
public string Title {get; set;}
public string Authors {get; set;} // for simplicity
public DateTimeOffset Created {get; set;}
public DateTimeOffset Updated {get; set;}
}ModelContext Must derive from DbContext and have appropriate DbSet<BookEntity>
public ModelContext : DbContext
{
// ...
DbSet<BookEntity> Books {get;set;}
}
- Create a
DTO- BookDto
public class BookDto
{
public int Id {get; set;}
public string Title {get; set;}
public string Authors {get; set;}
}- Create a factory function
public static class BookFactory
{
public static BookDto Create(BookEntity entity)
{
return new BookDto
{
Id = entity.Id,
Title = entity.Title,
Authors = entity.Authors;
};
}
}- That's all