Skip to content

Instantly share code, notes, and snippets.

@Kevin-Bronsdijk
Created August 23, 2016 06:21
Show Gist options
  • Save Kevin-Bronsdijk/c73a7d55bfc8ea6454184ac34c7778c4 to your computer and use it in GitHub Desktop.
Save Kevin-Bronsdijk/c73a7d55bfc8ea6454184ac34c7778c4 to your computer and use it in GitHub Desktop.
Azure Functions devslice.net
#r "Newtonsoft.Json"
using System;
using System.Net;
using Newtonsoft.Json;
using GTmetrix;
using GTmetrix.Http;
using GTmetrix.Model;
public static async Task<object> Run(HttpRequestMessage req, TraceWriter log)
{
string jsonContent = await req.Content.ReadAsStringAsync();
dynamic data = JsonConvert.DeserializeObject(jsonContent);
if (data.url == null) {
return req.CreateResponse(HttpStatusCode.BadRequest, new {
error = "Please provide a url"
});
}
var client = new Client(Connection.Create("your_key", "your_username"));
var response = client.SubmitTestAsync(new TestRequest(
new Uri(data.url.ToString()),
Locations.London,
Browsers.Chrome));
var result = response.Result;
return req.CreateResponse(response.Result.StatusCode, response.Result);
}
{
"frameworks": {
"net46":{
"dependencies": {
"GTmetrix": "0.1.0"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment