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.
- Install the Azure Functions for Visual Studio Code extension
-
Clone this repository
git clone https://github.com/simonaco/pbp-serverless.git cd pbp-serverless
-
Install the npm packages
npm i
-
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": "*" } }
-
Go to Angular Cosmos DB and follow steps to get started and run the app there
-
Open the application in VS Code and run application
-
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';
-
In VS Code go to Azure Functions extension and follow steps in this video
-
In the Azure portal go to your newly published function app and copy URL
-
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