Clean Architecture — ASP.NET Core REST API with OData and Swagger UI

Discussing how to provide GraphQL like experience in the REST API using OData and Swagger UI.

Shawn Shi
2 min readOct 3, 2020

UPDATE April 10, 2022: all projects in the GitHub repo have been upgraded to .NET 5.

This article extends the Clean Architecture — ASP.NET Core Partitioned Repository Pattern Using Azure Cosmos DB, where Clean Architecture, Database Partitioning, and Partitioned Repository Pattern are discussed.

What do you do when you have a RESTful API endpoint that returns a giant resource payload, but your client application only needs a small piece?

For example, my GET ToDoItem endpoint returns the following data by default.

Default response (Image by Author)

What if all I really only need are the titles? Well the solution is to allow the URL: https://localhost:5001/api/ToDoItem?$select=title to return only the titles like below. You see how the payload is drastically reduced.

(Image by Author)

In this article, I will discuss how the above feature can be done by adding OData on REST API built…

--

--

Shawn Shi
Shawn Shi

Written by Shawn Shi

Senior Software Engineer at Microsoft. Ex-Machine Learning Engineer. When I am not building applications, I am playing with my kids or outside rock climbing!