Skip to content

Instantly share code, notes, and snippets.

@shibayan
Last active November 26, 2015 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shibayan/23425f9f68a91937b7ad to your computer and use it in GitHub Desktop.
Save shibayan/23425f9f68a91937b7ad to your computer and use it in GitHub Desktop.
Simple Fastly C# Client
public class Fastly
{
public Fastly(string fastlyKey)
{
_fastlyKey = fastlyKey;
}
private readonly string _fastlyKey;
private const string EntryPoint = "https://api.fastly.com";
public Task Purge(string uri)
{
return Purge(new Uri(uri));
}
public Task Purge(Uri uri)
{
return SendAsync("PURGE", uri);
}
public Task PurgeKey(string service, string key)
{
var uri = $"{EntryPoint}/service/{WebUtility.UrlEncode(service)}/purge/{key}";
return SendAsync("POST", new Uri(uri));
}
public Task PurgeAll(string service)
{
var uri = $"{EntryPoint}/service/{WebUtility.UrlEncode(service)}/purge_all";
return SendAsync("POST", new Uri(uri));
}
private Task SendAsync(string method, Uri requestUri)
{
var request = new HttpRequestMessage
{
Method = new HttpMethod(method),
RequestUri = requestUri
};
request.Headers.Add("Accept", "application/json");
request.Headers.Add("Fastly-Key", _fastlyKey);
var client = new HttpClient();
return client.SendAsync(request);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment