This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bytes" | |
"encoding/binary" | |
"fmt" | |
"math/bits" | |
) | |
func main() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat azuredeploy.json | |
{ | |
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", | |
"contentVersion": "1.0.0.0", | |
"parameters": { | |
}, | |
"variables": { | |
}, | |
"resources": [ | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[FunctionName("SomeFunc")] | |
public static async Task SomeFunc([EventGridTrigger] EventGridEvent eventGridEvent, TraceWriter log) | |
{ | |
var data = JsonConvert.SerializeObject(eventGridEvent); | |
log.Info($"The SomeFunc : {data}"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class EventGridEvent | |
{ | |
public EventGridEvent(); | |
[JsonProperty(PropertyName = "topic")] | |
public string Topic { get; set; } | |
[JsonProperty(PropertyName = "subject")] | |
public string Subject { get; set; } | |
[JsonProperty(PropertyName = "data")] | |
public JObject Data { get; set; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static async Task sendEventGridMessageWithEventGridClientAsync(string topicHostName, string subject, object data) | |
{ | |
var credentials = new Microsoft.Azure.EventGrid.Models.TopicCredentials(topicKey); | |
var client = new Microsoft.Azure.EventGrid.EventGridClient(credentials); | |
var eventGridEvent = new Microsoft.Azure.EventGrid.Models.EventGridEvent | |
{ | |
Subject = subject, | |
EventType = "func-event", | |
EventTime = DateTime.UtcNow, | |
Id = Guid.NewGuid().ToString(), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[FunctionName("HttpHook")] | |
public static async Task<HttpResponseMessage> HttpHook([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)]HttpRequestMessage req, TraceWriter log) | |
{ | |
var body = await req.Content.ReadAsStringAsync(); | |
log.Info($"HttpHook hooked: {body}"); | |
return req.CreateResponse(HttpStatusCode.OK, new { greeting = "hello" }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[FunctionName("Merger")] | |
public static async Task Merge([EventGridTrigger] EventGridEvent eventGridEvent, TraceWriter log) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.IO; | |
using Microsoft.AspNetCore.Mvc; | |
using Microsoft.Azure.WebJobs; | |
using Microsoft.Azure.WebJobs.Extensions.Http; | |
using Microsoft.AspNetCore.Http; | |
using Microsoft.Azure.WebJobs.Host; | |
using Newtonsoft.Json; | |
using System.Net.Http; | |
using System.Threading.Tasks; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[FunctionName(“HttpTrigger”)] | |
public async static Task<IActionResult> RunAsync([HttpTrigger(AuthorizationLevel.Function, “get”, “post”, Route = null)]HttpRequest req, TraceWriter log) | |
{ | |
log.Info(“C# HTTP trigger function processed a request.”); | |
string name = req.Query[“name”]; | |
string requestBody = new StreamReader(req.Body).ReadToEnd(); | |
dynamic data = JsonConvert.DeserializeObject(requestBody); | |
name = name ?? data?.name; | |
return name != null | |
? (ActionResult)new OkObjectResult($”Hello, {name}”) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestClass] | |
public class HttpTriggerTest : FunctionTestHelper.FunctionTest | |
{ | |
[TestMethod] | |
public async Task Request_With_Query() |