NetCore REST API CRUD, Filter, Sort, Page, and Shape Data with VS Template OnionAPI
I have been searching for a Visual Studio template to generate a Clean Architecture ASP.NET Core REST API solution with boilerplate code for advanced features such as data CRUD, filtering, sorting, paging, and shaping using EntityFramework. Unable to find one, I cooked up the OnionAPI template and served it up for free download in the Visual Studio marketplace.
In this story, I will go over the steps to download/install the OnionAPI template into Visual Studio 2019 and then use the template to scaffold a new REST API project. You will find a complimentary Youtube video and Github source code for download at the end of this story.
Let’s get started.
Credit Where Credit Is Due
To develop this Visual Studio template, I have reviewed and integrated tools and techniques from the following sources
- ASP.NET Core WebAPI Clean Architecture template from Mukesh Murugan
- Data Shaping in ASP.NET Core Web API from CodeMaze
Overview of OnionAPI template
Developers can use the Visual Studio template OnionAPI to scaffold a clean architecture (onion view) ASP.NET Core REST API project. Now you know where the name OnionAPI coming from (:
You provide the project name and the template will create five (5) projects inside the solution. Each project is prefixed with the project name and has proper project namespaces in the source code.
- Domain — for entities and the common models
- Application —for Interfaces, CQRS Features, Exceptions, Behaviors
- Infrastructure.Persistence — for application-specific database access
- Infrastructure.Shared — for common services such as Mail Service, Date Time Service, Mock, and so on
- WebApi — for controllers to expose REST API resources and endpoints
The below screenshot depicts the organization of 5 projects in the Visual Studio solution after the template generated source code for the sample project name TalentManagement.

The solution tech stack provides loosely-coupled and inverted-dependency architecture with good design patterns and practices.
- ASP.NET CORE 5 — a framework for creating RESTful services, also known as web APIs, using C#
- Repository Pattern — abstraction layer between the data access layer and the controller
- CQRS (Command and Query Responsibility Segregation) Pattern — separating read and update operations for a data store to maximize performance, scalability, and security
- Entity Framework Core — a lightweight, extensible, open-source, and cross-platform version of the popular Entity Framework data access technology
- Swashbuckle— Seamlessly adds a Swagger to WebApi projects! Combines ApiExplorer and Swagger/swagger-ui to provide a rich discovery, documentation, and playground experience to your API consumers
- Bogus — providing realistic, easy to use mock data .NET library for rapid REST API design and testing
Download OnionAPI Template
You can download the OnionAPI template from the Visual Studio Marketplace.
After download, click on the VSIXTemplateOnionAPI.vsix to install the extension. If you are new to Visual Studio Extension, visit Manage extensions for Visual Studio for installation instructions.

Generate a New REST API Project with OnionAPI Template
The easiest way to create a new project is to start from a project template for a particular type of application or website. A project template consists of a basic set of pre-generated code files, config files, assets, and settings.
When you first open Visual Studio, the start window appears, and from there, you can choose to create a new project.
If the Visual Studio development environment is already open, you can create a new project by choosing File > New > Project on the menu bar or by clicking the New Project button on the toolbar.
Task 1 — Select a Template Type
On the Create a new project page, a list of your recently selected templates appears on the left. The templates are sorted by most recently used.
If you’re not selecting from the recently used templates, you can filter all available project templates by entering search text into the search box to further filter the templates, for example, “OnionAPI”.

Task 2 — Create a Solution
On the Create a new project screen, search for and select the OnionAPI template and click on the Next button

Enter the project name (ex. TalentManagement) and click on the Create button

Right-mouse click on TalentManagement.WebApi and Set as Startup Project

Hit F5 to run. The swagger should show in the browser

Task 2 — Try Out Filtering, Sorting, Shaping, and Paging Features
The OnionAPI template creates two REST resources
- Employees — This is a mock REST API resource where the data is dynamically generated by Bogus library at run time. To learn more about Bogus, check the link in the Related Stories section later on.
- Positions — This REST API resource gets its data from the actual database table Positions. This table is automatically seeded with 1,000 rows of fake data when the project first run.

To try out REST API in Swagger
- Click on Employees > GET to expand the screen
- Click on Try it out
- Enter parameters (can leave blank to use default values)
- Click on the Execute button
- Review the JSON output


