From the course: Advanced Web APIs with ASP.NET Core in .NET 6

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Consuming the API with JavaScript

Consuming the API with JavaScript - C# Tutorial

From the course: Advanced Web APIs with ASP.NET Core in .NET 6

Consuming the API with JavaScript

[Narrator] When consuming our API from JavaScript there are certain security aspects that we need to keep in mind. Let me show you. First of all, I'm adding a new project to our solution and this time I'm using an ASP.NetCore web app. So basically, razor pages. I'll call it HPlusSport.Web and leave the remaining settings as is. And then on the one page that is created index CSHML, I'll ignore error in privacy. I will add some output. And the output will be the list of products that the API returns. So I'll start by adding an unordered list. Let's call it maybe products list and I'll fill that with JavaScript. So the template defines a script section which will be rendered towards the end of the page. And in that section, I'll put my script tag and my code that will call the URL. Well, the URL is of course, the URL of the existing API. So let's double check with the settings we have here. So the base URL is local…

Contents