Skip to content

Latest commit

 

History

History
84 lines (55 loc) · 3.06 KB

README.md

File metadata and controls

84 lines (55 loc) · 3.06 KB

CRUD Serverless API

This project represents a fully serverless implementation for a CRUD (Create, Retrieve, Update, Delete) API implemented with Azure Functions and Azure Cosmos DB.

For the purpose of this demo we are going to use an Angular application built by John Papa. The code for this application is available on Github at Angular Cosmos DB.

You can watch John Papa and I talk about this project in this Pluralsight course.

Requirements

  1. Install the Azure Functions for Visual Studio Code extension

Getting Started

  1. Clone this repository

    git clone https://github.com/simonaco/pbp-serverless.git
    cd pbp-serverless
  2. Install the npm packages

    npm i
  3. Configure Cosmos DB server settings

    Go to local.settings.json in the project root and update it with your Cosmos DB settings. If the file doesn't exist, make sure to create it. Replace the database name, password and port with your specific configuration.

    // local.settings.json
    {
    "IsEncrypted": false,
        "Values": {
            "AzureWebJobsStorage": "",
            "CosmosDBURL": "mongodb://<your-HOST-goes-here>:<your-PORT-goes-here>/?ssl=true",
            "CosmosDBUser": "<your-USERNAME-goes-here>",
            "CosmosDBPass": "<your-PASSWORD-goes-here>",
            "CosmosDB": "<your-cosmos-db-name-goes-here>"
        },
        "Host": {
            "LocalHttpPort": 7071,
            "CORS": "*"
        }
    }
  4. Go to Angular Cosmos DB and follow steps to get started and run the app there

Running the application locally

  1. Open the application in VS Code and run application

    Run Azure Functions locally in VS Code

  2. Assuming you went through the steps of installing and running your Angular application locally now open the app in VS Code and go to hero.service.ts and configure your endpoint to be the newly created functions:

    const api = 'http://localhost:7071/api';

Publish your API to the cloud

  1. In VS Code go to Azure Functions extension and follow steps in this video

  2. In the Azure portal go to your newly published function app and copy URL

    Get Function URL from the Azure portal

  3. In your Angular app go to hero.service.ts and configure your endpoint to point to the newly deployed function:

    const api = 'https://sicotin-serverless.azurewebsites.net/api';

If you're looking for more use cases on what you can build with serverless make sure to checkout An open source set of common use cases for Azure Functions

Problems or Suggestions

Open an issue here