Create an ASP.NET Core WebAPI with the dotnet cli and Visual Studio Code

Share this video with your friends

Send Tweet

To build a quick backend solution which we can communicate with can sometimes be challenging and takes a lot of time. In this course we will learn how we can create an ASP.NET Core WebAPI with the dotnet command line interface and how we can query our first data from that REST endpoint.

To see how to consume this ASP.NET endpoint: Display Values from an ASP.NET Core API in your Angular Components

Harri Jauri
~ 7 years ago

The cors middleware configuration is missing. That means that we can't access these endpoints from angular client run with ng serve on port 4200 (from lesson Display Values from an ASP.NET Core API in your Angular Components).

To configure cors to allow access from port 4200, add these lines to corresponding methods in Startup.cs

public void ConfigureServices(IServiceCollection services)
{
  services.AddCors();
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
  app.UseCors(builder => builder.WithOrigins("http://localhost:4200"));
}
Fabian Gosebrinkinstructor
~ 7 years ago

Hey Harri,

thanks for you comment. That is true, sorry that I did not point that out. I added CORS in the corresponding github repository.

https://github.com/FabianGosebrink/egghead-creating-a-aspnet-core-webapi-with-the-dotnet-cli

Cheers and thank you very much!

Fabian

Henry Lee
~ 6 years ago

Nice straight forward and simple to intro dotnet cli for .NET webapi. Looking forward to have .NET tutorial from you later. (if you can have make a webapi on auth token, then will be nice)