Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Advanced Serverless Architectures with Microsoft Azure

You're reading from  Advanced Serverless Architectures with Microsoft Azure

Product type Book
Published in Feb 2019
Publisher Packt
ISBN-13 9781788479127
Pages 278 pages
Edition 1st Edition
Languages
Concepts
Author (1):
Daniel Bass Daniel Bass
Author Profile Icon Daniel Bass
Daniel Bass
Toc

Chapter 1: Complete Serverless Architectures


Activity 1: Creating a Serverless Application for Viewing User Data

  1. Open the Azure Portal and click on the New Collection option to create a new collection called users in the Cosmos DB database named serverless.

  2. Click on Documents inside the Collection, and then click on the New Document option to insert user data into the Cosmos DB. Create a user using the following JSON:

    {
      "name": "Daniel",
      "emailAddress": "no@email.com"
    }
  3. Using the function from Exercise 4, Displaying Product Data on your Serverless Website, as a template, read the user data from the Cosmos DB and return it. Make the following changes to the function body:

    public static async Task<List<User>> Run([HttpTrigger(AuthorizationLevel.Function, "get", Route = null)]HttpRequest req, ILogger log)

    Figure 1.61: Function reading users from Cosmos DB

  4. Now, use the index.html file from Exercise 4, Displaying Product Data on your Serverless Website, as a template, and create an index.html file in a folder called website. Adjust it to read from the GetUsers function using the following code:

    fetch('http://localhost:7071/api/GetUsers')

    Display the data in a table, using the following code for the function body:

    function rowOfDataFromObject(data){
      let row = document.createElement('tr');
      let nameTableElement = document.createElement('td');
    
      nameTableElement.appendChild(document.createTextNode(data.name))
      row.appendChild(nameTableElement);
    
      let emailTableElement = document.createElement('td');
    
      emailTableElement.appendChild(document.createTextNode(data.email))
      row.appendChild(emailTableElement);
    
      return row;

    Figure 1.62: index.html displaying users

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime