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

Unlock the full course today

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

Consuming the API with JavaScript

Consuming the API with JavaScript

- [Instructor] There are certain security restrictions when using JavaScript to consume the API from another site, and the only place where we can fix that, or make the JavaScript client and the API communicate well, is in the API. So I'm about to write some JavaScript code that will eventually fail, but I promise we'll fix it later. But bear with me until we are done there. So I am adding a new project to our solution, and I'm using ASP.NET Core Web App, so project template is web. I'm using Razor Pages just because it's quick and painless, and HPlusSporty.Web is a good name for that web application. Default settings, you can use HTTPS, all good. And in that new web project, we have a couple of pages, including an index page, and I would like to add that code to the index page. The idea of the JavaScript code is that the JavaScript code consumes the API and calls the /product endpoint and then just displays all of the products. For that, we need a placeholder first, a list where…

Contents