We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.

Wayne Molina • 4 years ago

This is a really good tutorial. I'm new to learning about Web API and I found this to be very clear and concise and have a solid working example that I can play around with.

CarloHerzl • 4 years ago

Thanks :)

Pravin Jadhav • 4 years ago


PigLHedis • 4 years ago

Thanks for the awesome tutorial. Very well article. I'm new for dotnet 7 days ago

CarloHerzl • 4 years ago

Hi, thank you so much for your feedback.

That's great.


¿For what do you use public int? StockItemID { get; set; } if in the database that data appears as not null?

CarloHerzl • 4 years ago

Hi, this is a good question but requires a big explanation, please read this link:Entity Framework Core 2 for the Enterprise

Section Entity Layer - Keys


keyman • 4 years ago

Thanks for the awesome tutorial 👍🏻 👍🏻 👍🏻

CarloHerzl • 4 years ago


Hermann Rösch • 4 years ago

Greetings Carlo! Hats off! Very well drafted article. It shows you're a top professional.

Thank you for the elaborated technique and the clarity! 👍🏻

CarloHerzl • 4 years ago

Thank you so much for your feedback.

Vedran Mandić • 5 years ago

Absolutely fantastic tutorial! Very good coverage of unit testing which is a huge plus.

CarloHerzl • 5 years ago

Thank you so much for your feedback

Pedro Faustino • 4 years ago


Could you provide an example of how to implement the test "Add a stock item without required fields"?
I'm having some problems because the method ModelState.IsValid() returns true when I pass NULL on a required field.

CarloHerzl • 4 years ago


In that case you can add another method in controller and use another model for request that fits with your requirements, please keep on mind You'll need to set default values for required columns that don't have values from request.


Anonymous • 2 years ago

This is a great explanation. Is there a source code to download ?

Anonymous • 3 years ago

this is so amazing, thanks for sharing your knowledge. It was very useful for me

Fenster • 3 years ago

A very good tutorial.

Achal_Prajapati • 4 years ago

This is a really awesome tutorial and great helpful.
Can you provide me source code or Git hub link.?

CarloHerzl • 4 years ago


The link is at beginning of this post, anyway this is: Source code.


Carlos Menezes • 4 years ago

Try and catch on every single method? Not sure if this is a good practise?

CarloHerzl • 4 years ago

Hi, thank you so much for your comment.

You have a good point and that's correct but remember this is a guide for beginners and the point is show how to deal with errors in a simple way.

Maybe in one future version I'll add the use of global error handler.


Jonathan Melendez Alva • 4 years ago


The code of the Entities.cs class can be self-generated or it is necessary to type the entire code.

Best regards

CarloHerzl • 4 years ago


In this case isn't necessary because We're working with an API for one entity (table), if You want to create an API for a couple of entities You can use scaffolding for Entity Framework Core.

Please read more information in this link: EF Core Tools & Extensions


Nilukshan Croos • 4 years ago

This is a really good tutorial. But one concern, It seems the DB migration command missing in this tutorial. No need to do that? Or it is necessary?

CarloHerzl • 4 years ago


This tutorial uses Database-First approach, You're talking about Code-First approach.


NilukshanCroos • 4 years ago

Okay thanks.

Star • 4 years ago

Fantastic Tutorial especial Integration testing and unit testing
Hi CarloHerzl could you plz do a favour for me , can you use .NET Core and stored procedures to display the information in a table and running all crud in a table by creating buttons

CarloHerzl • 4 years ago

Hi, thank you so much for your feedback.

Do you mean change this tutorial and use stored procedures?

Star808Star • 4 years ago

Absolutely CarloHerzl please use stored procedures and .Net Core and also implement all the CRUD and use a controller to call all the CRUD form stored procedures . Your help would be highly appreciated

Anonymous • 4 years ago

Can anyone tell me why I would get the following error in WarehouseController.cs

Line with Error: response.Model = await query.Paging(pageSize,pageNumber).ToListAsync();

Error: Severity Code Description Project File Line Suppression State
Error CS1061 'IQueryable<stockitem>' does not contain a definition for 'Paging' and no accessible extension method 'Paging' accepting a first argument of type 'IQueryable<stockitem>' could be found (are you missing a using directive or an assembly reference?) WideWorldImporters.API C:\Projects\WideWorldImporters.API\WideWorldImporters.API\Controllers\WarehouseController.cs 63 Active

Thank You!

CarloHerzl • 4 years ago

You have missed to add the extension method, please make sure you have added IQueryableExtensions class in Extensions.cs file

me moi • 4 years ago


Fernando • 4 years ago

Thank you.

Because you put as a requirement nodejs?

CarloHerzl • 4 years ago

Hi Fernando.

You're right, NodeJS is not a requirement for this tutorial.


Mbathason • 4 years ago

This is an awesome introduction to building web APIs with ASP.Net Core. It's straight-forward and easy to follow. Some issues I came across:

1. I had to configure `launchSettings.json` as follows:
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:63166",
"sslPort": 0
"$schema": "http://json.schemastore.org...",
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"WideWorldImporters.API": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "api/v1/Warehouse/StockItem",
"environmentVariables": {
"applicationUrl": "http://localhost:5000"

I had to set launch URL for IIS Express and WideWorldImporters.API.

2. My connection string had to be "Data Source=(local);Initial Catalog=WideWorldImporters;Integrated Security=True".

3. (Suggestion) Make the code easier to copy and paste.

This is great and I look forward to learning more from you.

Hardie Light Lorenzo • 4 years ago

Thanks for this. It help me

aku • 4 years ago

What does it do? I always hit internal server error 500 for integration testing. And cannot extract specific error message. I cannot find a way to extract it from http client. Any suggestion?

Chris • 3 years ago

I'm also getting the 500 server error. System.Net.Http.HttpRequestException : Response status code does not indicate success: 500 (Internal Server Error). It doesn't hit any more my break points Does anyone know of a solution or encounter something like this?

Vikash Sharma • 4 years ago

Thank you ! i was looking exactly for this. I just loved and used in my project.
public static IActionResult ToHttpResponse(this IResponse response) is there then ToHttpResponse is available for all the concrete who used this interface so if rather than extension method decides what httpstatus going to send can we pass it from response object ? if we do that than we dont have to wrtite 2 more overriders ?

i am still learning best practice but the architecture you are followed while defining models under namespace WideWorldImporters.API.Models, like inheriting from interfaces and generic, what purpose they solve ?

CarloHerzl • 4 years ago


IResponse represents a response with no model, We can use this response for Update and Delete actions because We don't need to return any value for client.

ISingleResponse<tmodel> represents a response with a model, for example StockItem; We can use this response for GetByID and Create actions because these responses need to have the StockItemID.

IListResponse<tmodel> and IPagedResponse<tmodel> represents a list response.

WideWorldImporters.API.Models namespace contains all definitions related to Web API, this guide is not about enterprise implementation so We have all definitions inside of same project.

A robust solution requires to have another project to place business logic and domain driven design but as I said before that design requires advanced skills in C#, you can read more about in: https://www.codeproject.com...

Let me know if this reply is useful.


Jennifer Cai • 4 years ago

I personally like this tutorial way more than what is provided by Microsoft, but I thought I'd link it here for anyone else who might be interested :)


CarloHerzl • 4 years ago

Hi, thank you so much for your feedback.

I don't understand what do you mean with link it, can you provide me more information please.


ycai • 4 years ago

Sorry for the confusion Carlo! I like your tutorial more than the Microsoft documentation / your tutorial is better.

But in case any other readers wanted to more information, I also provided the link (web address) to the Microsoft documentation here: https://docs.microsoft.com/...

CarloHerzl • 4 years ago

I already added the link, thank you so much for your feedback.