REST API access

After creating the initial layout, let's implement the API access layer by encapsulating it in its own dedicated file and namespace:

  1. Create a file named api.js and implement the REST API query calls:
'use-strict';(function (window) {  const ns = window.api = window.api || {};  // EDIT the URL with the the address of your REST API -  const baseUrl = 'http://localhost:55564/api';  // build the URL for a REST API call and include the parameters  function getApiAction(action, parameters = null) {    const p = (!parameters || parameters.length === 0)      ? ''      : `/${Object.values(parameters).join('/')}`;    return `${baseUrl}/${action}${p}`;  } // iterate through products returned from REST API and set the primary image accordingly for each product ...

Get Hands-On Full-Stack Web Development with ASP.NET Core now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.