Http Trigger #Azure functions with CosmosDB SQL API #serverless

Examples how to get routing parameters with SQL API working for Cosmos DB in Azure functions.

Published 17th of October 2018
Version .net 4.7

All these example are used in the back end of this app Find an Episerver Partner with Certified Developers

Http Trigger Function apps

Example 1: Getting data from Cosmos DB with SQL API and routing parameter then deserializing the data to custom object.

Test URL: https://gosso-epiworld.azurewebsites.net/api/GetDevs/CmsCert/Gosso Systems AB

Route = “GetDevs/{type}/{company}” and then using {type} in SQL:

[DocumentDB(Manager.DatabaseName, “devs”, ConnectionStringSetting = Manager.DbConnString, SqlQuery = “SELECT top 1 * FROM c where c.type={type} and c.count>0 order by c._ts desc”)]

Business logic (Manager) and structs:

Example 2: Getting data from Cosmos DB with SQL API and routing parameter then deserializing the data to custom object. Grouping devs by Company

Test URL: https://gosso-epiworld.azurewebsites.net/api/GetCompanies/ComCert/

 

Example 3: Get a subsequence of the data from cosmos, retrieve and return a smaller json for statistics.

Used here: https://devblog.gosso.se/find-an-episerver-certified-dev-company/certification-over-time/

Test url: https://gosso-epiworld.azurewebsites.net/api/GetStatsByDate/ComCert/

 

Tip: Local diagnostics with System.Diagnostics.Trace.WriteLine(message);

Further reading and testing

SEO Terms

  • Serverless Cosmos db example
  • Using routing in function app

About the author

Image of Luc GossoLuc Gosso
– Independent Senior Web Developer
working with Azure and Episerver

Twitter: @LucGosso
LinkedIn: linkedin.com/in/luc-gosso/
Github: github.com/lucgosso

Like it? please up vote
-1