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
  1. //HTTP Restful client (sudo code)
  2. // Get data
  3. rest.Get(requestUrl);
  4. // Save data
  5. rest.Add(paramKey, paramValue);
  6. rest.Post(requestUrl, data);
  7. // Delete data
  8. rest.Delete(requestUrl);
  9. //Azure Storage or Redis ache sudo-code
  10. // Get data
  11. rest.Get<Stream>("/container/filePath");
  12. rest.Get("/container/jsonData");
  13. rest.Get<myObject>("/container/filePath");
  14. // Save data
  15. rest.Post<myObject>("/container/filePath", myObject);
  16. // Delete data
  17. rest.Delete("/container/filePath");
Detailed Examples
  1. Use it as a basic RESTful HTTP Client.
    1. //direct string JSON return
    2. var rest = new Restme(new Uri("http://freegeoip.net"));
    3. var result1 = rest.Get("/json/github.com");
    4. //automatic Generic cast
    5. var result2 = rest.Get < MyObject > ("/json/github.com");
    6. var resultAsync2 = await rest.GetAsync << MyObjecT > ("/json/github.com");
    7. //add parameters (Parameters get automatically converted into query string or post form fields)
    8. rest.add("q", "github.com");
    9. var result3 = rest.Get < MyObject > ("/json");
    10. var resultAsync3 = await rest.GetAsync < MyObjecT > ("/json");
    11. //supports POST, DELETE, PUT etc.
    12. var rest2 = new Restme(new Uri("http://example.com"));
    13. rest2.Add("Username", "[email protected]");
    14. rest2.Add("Birthday", DateTime.UtcNow);
    15. rest2.Post < MyObject > ("/someurl");
    16. rest3.PostAsync < MyObject > ("/asyncexample");
    17. //supports direct object submission
    18. var myObject = new MyObject()
    19. {
    20. Username = "[email protected]",
    21. Birthday = DateTime.UtcNow
    22. };
    23. var rest3 = new Restme(new Uri("http://example.com"));
    24. rest3.Add(myObject);
    25. rest3.Post < ExpectedResultObject > ("/directObjectPost");
  2. Use it as an Azure Storage Client,
    1. //get blob stream directly
    2. var blobStorageConnectionString = "{Your Storage Account Connection String}";
    3. var rest = new Restme(blobStorageConnetionString);
    4. rest.CreateAzureBlobContainerIfNotExists = true; //do this only if you want to auto create the container
    5. //NOTE 1: first segment of the path should always be your container name
    6. //NOTE 3: Type T: if it is a type of Stream it will be stored as original Stream as Azure Blob, otherwise it is always saved into JSON format as Azure Blob
    7. //NOTE 2: use a type of Stream if you want the original value retrieved from the blob
    8. rest.Get < Stream > ("/myContainer/myfilePath");
    9. rest.GetAsync < Stream > ("/myContainer/myfilePath");
    10. //NOTE: only blob items saved in JSON format is suppported
    11. rest.Get < ObjectType > ("/myContainer/myfileObjectInJSONFileFormat");
    12. rest.GetAsync < ObjectType > ("/myContainer/myfileObjectInJSONFileFormat");
  3. Use it as a Redis Cache Client,
    1. var redisConnectionString = "{Your Redis Cache Connection String}";
    2. var rest = new Restme(redisConnectionString);
    3. //get cache data (support Generic cast)
    4. var cacheResult = rest.Get("home:testKey");
    5. var cacheResult2 = rest.Get<bool>("home:testKey2");
    6. var cacheResult3 = rest.Get<ObjectType>("home:testKey3");
    7. //set cache data
    8. rest.Post("home:testKey","value");
    9. rest.Post<bool>("home:testKey2",true);
    10. var myObject = new ObjectType(); //will be serialized into JSON format and stored as string on redis server
    11. rest.Post<ObjectType>("home:testKey3", myObject);
I've made the code open source under MIT on github.