1
0
mirror of https://github.com/Microsoft/sql-server-samples.git synced 2025-12-08 14:58:54 +00:00

Added example with Azure Function REST API

This commit is contained in:
Jovan Popovic
2017-03-13 23:03:08 +01:00
parent 7ea97a05d7
commit 8a86a7ff2d
3 changed files with 115 additions and 0 deletions

View File

@ -0,0 +1,24 @@
using System.Net;
using System.Configuration;
using Belgrade.SqlClient;
using Belgrade.SqlClient.SqlDb;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
try{
string ConnectionString = ConfigurationManager.ConnectionStrings["azure-db-connection"].ConnectionString;
var httpStatus = HttpStatusCode.OK;
string body =
await (new QueryMapper(ConnectionString)
.OnError(ex => { httpStatus = HttpStatusCode.InternalServerError; }))
.GetStringAsync("select * from sys.objects for json path");
return new HttpResponseMessage() { Content = new StringContent(body), StatusCode = httpStatus };
} catch (Exception ex) {
log.Error($"C# Http trigger function exception: {ex.Message}");
return new HttpResponseMessage() { Content = new StringContent(""), StatusCode = HttpStatusCode.InternalServerError };
}
}