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 - ASP.NET Core Tutorial
From the course: Advanced Web APIs with ASP.NET Core 8
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
Introduction: Securing APIs33s
-
(Locked)
Redirecting to HTTPS3m 48s
-
(Locked)
Enforcing HTTPS3m 57s
-
(Locked)
Consuming the API with JavaScript7m 32s
-
(Locked)
Cross-origin resource sharing (CORS)3m 42s
-
(Locked)
Enabling CORS5m 32s
-
(Locked)
Adding ASP.NET Core Identity9m 34s
-
(Locked)
Adding token authentication8m 42s
-
(Locked)
-