Building APIs with C# and ASP.NET Core

Reviewing the Application

Spencer Schneidenbach

Spencer Schneidenbach

Aviron Software, Microsoft MVP
Building APIs with C# and ASP.NET Core

Check out a free preview of the full Building APIs with C# and ASP.NET Core course

The "Reviewing the Application" Lesson is part of the full, Building APIs with C# and ASP.NET Core course featured in this preview video. Here's what you'd learn in this lesson:

Spencer spends a few minutes reviewing everything built into the EmployeeAPI project. The API uses entities to represent and store data and respects the Single Responsibility Principle.

Preview
Close

Transcript from the "Reviewing the Application" Lesson

[00:00:00]
>> Spencer Schneidenbach: A brief overview of everything we've done. We have run through the gauntlet, we have made an application that I am frankly very proud of because it is something that I would write. It is covered by tests, it is well organized, it is well documented, it's all the things that I personally love in an API.

[00:00:16]
We removed the in-memory repository, that stupid list, and we replaced it with a real, actual database, SQLite. We seeded that database, we extended the get all employees endpoint to add a way to filter and paginate data, which is very important. We changed the way we modeled and handled benefits, and we did a lot of database stuff under the hood.

[00:00:35]
We took in what I would consider to be, in this course, the most significant refactor. So, it's pretty crazy. We made a decision early on to use request objects and I thought this was a good opportunity to kind of revisit that. When you get into something like EF Core where you have a series of entities where they all are related in some way and those relationships go down very deep.

[00:01:00]
You will find that request objects really, really do start to pay off, because the moment you try to return stop returning entities and start returning request objects is when you stop getting into certain issues. I had a client that had a very complex data set, and they did return entities right away.

[00:01:21]
And they found that suddenly some of their APIs were failing because JSON was finding circular dependencies, or circular properties. Properties that refer back to one another between two objects or the data model was returning megabytes of data when really it only needed to return not even a kilobyte.

[00:01:38]
So the impact of this cannot be understated. We did this early on, it may seem like a small thing that we did, but it actually down the road as our application grows. It does have huge implications, and it does respect the single responsibility principle. Unittaskers in the kitchen, maybe not, unitaskers in real in programming, definitely.

[00:02:01]
So that the remainder of the course, cuz we are at the end, I'm gonna show you just a couple of other things that I think are useful for you to know, things that common patterns that I see. I'm gonna talk a little bit about security, because I do think it's worth mentioning.

[00:02:14]
I'm gonna demonstrate a little bit of security inside of a sample project that you can take and write run from the code. And we're gonna talk about using actual real databases, not just SQLite, because there are problems with using SQLite, but for the purposes of this application, it works pretty well.

[00:02:32]
However, the thing that I'm gonna give you will allow you to use a real database, a real postgress database, or SQL Server database if you want, and very easy to learn.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now