danielwertheim

danielwertheim


notes from a passionate developer

Share


Sections


Tags


Disclaimer

This is a personal blog. The opinions expressed here represent my own and not those of my employer, nor current or previous. All content is published "as is", without warranty of any kind and I don't take any responsibility and can't be liable for any claims, damages or other liabilities that might be caused by the content.

Introducing MyCouch - a Simple async CouchDb client for .Net

Just got a new NuGet out – “MyCouch – a Simple async CouchDb client for .Net” – which uses the async HTTP-client to interact with the HTTP API of CouchDb. It tries to mimic the domain-language and structure of CouchDb and lets you work with pure JSON or using entities/POCOs. The future will bring builtin support for caching, proxies/sharding, etc. Go grab it now and try it out. It’s on NuGet. Documentation is improved continuously.

It’s simple to get started with

install-package mycouch
using (var client = new Client("http://127.0.0.1:5984/test"))
{
    //Consume here e.g
    var response1 = client.Documents.Post(json);

    //or using the async API
    var response2 = client.Documents.PostAsync(json);

    //Simple get
    var getResponseOfJson = client.Documents.Get("someid");
    var json = getResponseOfJson.Content;

    //or using an entity
    var getResponseOfEntity = client.Documents.Get<MyEntity>("someid");

    //or querying using views
    var viewResponse = client.Views.Query<MyEntity[]>(q => q
        .StartKey("foo")
        .EndKey("bar")
        .Skip(2)
        .Limit(5));

    foreach (var myEntity in viewResponse.Rows) {
        //Do something with your entity.
    }
}

Every action will give you a response in turn. The response gives you information about state etc:

{
    RequestUri: http://127.0.0.1:5984/test/1
    RequestMethod: GET
    Status: OK(200)
    Error:<NULL>
    Reason: <NULL>
    Id: 1
    Rev: 34-e0813c9f99766efcf679468adb02c6ce
    Content: {
        "_id":"1",
        "_rev":"34-e0813c9f99766efcf679468adb02c6ce",
        "$doctype":"artist",
        "name":"Fake artist 1",
        "albums":[{"name":"Greatest fakes #1"}]}
}

Well that’s it for now. More info will come.

//Daniel

View Comments