Skip to content

Instantly share code, notes, and snippets.

@pradeepmurugan
Created January 22, 2019 18:25
Show Gist options
  • Save pradeepmurugan/a406cbf126845d3e176f4564594224a5 to your computer and use it in GitHub Desktop.
Save pradeepmurugan/a406cbf126845d3e176f4564594224a5 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
namespace FunctionApp3
{
public static class Function1
{
[FunctionName("Function1")]
public static async Task RunAsync([BlobTrigger("pelcontainer/{name}", Connection = "AzureWebJobsStorage")]Stream myBlob, string name, ILogger log)
{
log.LogInformation($"blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
var serializer = new JsonSerializer();
string result1 = await ConsumeRest();
using (var r = new StreamReader(myBlob))
{
string json = r.ReadToEnd();
List<Employee> items = JsonConvert.DeserializeObject<List<Employee>>(json);
foreach (var value in items)
{
log.LogInformation($"{value.fname} ");
}
log.LogInformation($"{result1} ");
}
}
public static async Task<string> ConsumeRest()
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("https://jsonplaceholder.typicode.com/posts/1");
var result = await client.GetAsync("");
string resultContent = await result.Content.ReadAsStringAsync();
return resultContent;
}
}
}
public class Employee
{
public string fname { get; set; }
public string lname { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment