Exyus is an HTTP/REST engine written for the Windows/ASP.NET platform. this blog lists code changes and other important updates to the code base.

2008-02-02

Tasklist-cmd Tutorial Posted

i posted a new tutorial (TaskList Client Tutorial) on the exyus site this evening. this one shows how to use the HTTPClient class inside exyus to create full-featured HTTP clients that run on your desktop instead of in your browser.

it was fun to put together. the app was easy (see my previous post on that). writing the tutorial was also pretty cool. not a lot to it, but it all falls together pretty nicely. the app allows you to list, add, edit, and delete records stored on the server. it uses HTTP commands (GET, PUT, POST, DELETE) and works like a champ. here's a sample of the code in the client app.

public XmlDocument GetList()
{
    client.RequestHeaders.Set("cache-control", "no-cache");
    string results = client.Execute(Uri, "get", "text/xml");
    XmlDocument doc = new XmlDocument();
    doc.LoadXml(results);
    return doc;
}

public XmlDocument GetItem(string id)
{
    string results = client.Execute(Uri + id, "get", "text/xml");
    p_etag = client.ResponseHeaders["etag"];
    XmlDocument doc = new XmlDocument();
    doc.LoadXml(results);
    return doc;
}

public void AddItem(string name)
{
    AddItem(name, "0");
}

public void AddItem(string name, string completed)
{
    client.Execute(Uri, "post", "text/xml", string.Format(p_new_task, name, completed));
}

you can check out the entire app (TaskList Client) at the exyus googlecode site.

No comments: