The new .NET Core is a platform framework that has finally come into my life to shake my coding style - now coding in my favorite OS - MacOSX.
Having spent a few hours in coding under .NET Core 1.0 (RC2), I created the RESTme toolkit. I originally was thinking to just create a RESTful client in the first hour, and then decided to make it more powerful by enabling it to communicate with Azure Storage and Redis Cache - why not? Since they are all about requesting and saving data!
General Code Example
-
-
- rest.Get(requestUrl);
-
- rest.Add(paramKey, paramValue);
- rest.Post(requestUrl, data);
-
- rest.Delete(requestUrl);
-
-
-
- rest.Get<Stream>("/container/filePath");
- rest.Get("/container/jsonData");
- rest.Get<myObject>("/container/filePath");
-
-
- rest.Post<myObject>("/container/filePath", myObject);
-
- rest.Delete("/container/filePath");
Detailed Examples
- Use it as a basic RESTful HTTP Client.
-
- var rest = new Restme(new Uri("http://freegeoip.net"));
- var result1 = rest.Get("/json/github.com");
-
-
- var result2 = rest.Get < MyObject > ("/json/github.com");
- var resultAsync2 = await rest.GetAsync << MyObjecT > ("/json/github.com");
-
-
- rest.add("q", "github.com");
- var result3 = rest.Get < MyObject > ("/json");
- var resultAsync3 = await rest.GetAsync < MyObjecT > ("/json");
-
-
- var rest2 = new Restme(new Uri("http://example.com"));
- rest2.Add("Username", "[email protected]");
- rest2.Add("Birthday", DateTime.UtcNow);
- rest2.Post < MyObject > ("/someurl");
-
- rest3.PostAsync < MyObject > ("/asyncexample");
-
-
-
- var myObject = new MyObject()
- {
- Username = "[email protected]",
- Birthday = DateTime.UtcNow
- };
- var rest3 = new Restme(new Uri("http://example.com"));
- rest3.Add(myObject);
- rest3.Post < ExpectedResultObject > ("/directObjectPost");
- Use it as an Azure Storage Client,
-
- var blobStorageConnectionString = "{Your Storage Account Connection String}";
-
-
- var rest = new Restme(blobStorageConnetionString);
-
-
- rest.CreateAzureBlobContainerIfNotExists = true;
-
-
-
-
-
-
-
-
-
-
-
- rest.Get < Stream > ("/myContainer/myfilePath");
-
- rest.GetAsync < Stream > ("/myContainer/myfilePath");
-
-
-
-
-
- rest.Get < ObjectType > ("/myContainer/myfileObjectInJSONFileFormat");
-
- rest.GetAsync < ObjectType > ("/myContainer/myfileObjectInJSONFileFormat");
- Use it as a Redis Cache Client,
- var redisConnectionString = "{Your Redis Cache Connection String}";
- var rest = new Restme(redisConnectionString);
-
-
- var cacheResult = rest.Get("home:testKey");
- var cacheResult2 = rest.Get<bool>("home:testKey2");
- var cacheResult3 = rest.Get<ObjectType>("home:testKey3");
-
-
- rest.Post("home:testKey","value");
- rest.Post<bool>("home:testKey2",true);
-
- var myObject = new ObjectType();
- rest.Post<ObjectType>("home:testKey3", myObject);
I've made the code open source under MIT on
github.