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

Wayne Molina • 2 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 • 2 years ago

Thanks :)

Pravin Jadhav • 1 year ago

...

PigLHedis • 2 years ago

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

CarloHerzl • 1 year ago

Hi, thank you so much for your feedback.

That's great.

Regards

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

CarloHerzl • 1 year 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

Regards

keyman • 2 years ago

Thanks for the awesome tutorial 👍🏻 👍🏻 👍🏻

CarloHerzl • 2 years ago

Thanks!

Hermann Rösch • 2 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 • 2 years ago

Thank you so much for your feedback.

Vedran Mandić • 2 years ago

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

CarloHerzl • 2 years ago

Thank you so much for your feedback

Pedro Faustino • 2 years ago

Hello,

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 • 1 year ago

Hi.

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.

Regards

Anonymous • 9 months ago

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

Anonymous • 12 months ago

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

Fenster • 1 year ago

A very good tutorial.

Achal_Prajapati • 1 year ago

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

CarloHerzl • 1 year ago

Hi,

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

Regards

Carlos Menezes • 1 year ago

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

CarloHerzl • 1 year 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.

Regards

Jonathan Melendez Alva • 2 years ago

Hi,

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

Best regards

CarloHerzl • 1 year ago

Hi.

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

Regards

Nilukshan Croos • 2 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 • 1 year ago

Hi.

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

Regards

NilukshanCroos • 1 year ago

Okay thanks.

Star • 2 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 • 2 years ago

Hi, thank you so much for your feedback.

Do you mean change this tutorial and use stored procedures?

Star808Star • 2 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 • 2 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 • 2 years ago

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

me moi • 2 years ago

WTF ?

Fernando • 2 years ago

Thank you.

Because you put as a requirement nodejs?

CarloHerzl • 2 years ago

Hi Fernando.

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

Regards

Mbathason • 2 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": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"WideWorldImporters.API": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "api/v1/Warehouse/StockItem",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"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 • 2 years ago

Thanks for this. It help me

aku • 2 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 • 1 year 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 • 2 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 • 2 years ago

Hi.

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.

Regards

Jennifer Cai • 2 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 :)

https://docs.microsoft.com/...

CarloHerzl • 2 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.

Regards

ycai • 2 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 • 2 years ago

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

Regards