I'm Keyvan Nayyeri, a 25 years old Ph.D. student at
the Computer Science department of
the University of Texas at San Antonio.
I'm also
a Software Architect and Developer and previously held a B.Sc.
degree in Applied Mathematics.
This is my blog where I publish content about various topics specifically Programming Languages and Compilers, Software
Engineering and Programming.
In the first two parts of this post series about Community Server REST API I introduced the API and covered the development model.
While these two posts would be enough for an ordinary developer (familiar with core Community Server architecture) to start developing applications with Community Server REST API, I thought it would be worth having an adjunct post that takes a pragmatic approach in the development with REST API by specializing in one of the subsystems like blog system.
Therefore, here is a post that covers development for blog APIs in REST API in general, and shows you the process in a nutshell without stepping in all details. I try to implement a few common scenarios in this post to exhibit my intention.
As the first example, I create a new blog group and set its properties then add it to the system, and finally delete it!
static void Main(string[] args)
{
Console.Title = "Community Server REST API - Blogs";
BlogsService service = new BlogsService("http://localhost/cs/", "admin", "2nw9q0ki");
BlogGroup group = new BlogGroup();
group.Name = "REST Blogs";
group.Description = "A sample blog group";
// Add
BlogGroup newGroup = service.AddBlogGroup(group);
Console.WriteLine("New blog group added.");
Console.WriteLine("New blog group name: {0}", newGroup.Name);
// Delete
newGroup.Delete();
Console.WriteLine("Blog group deleted.");
Console.ReadLine();
}
Here I create a BlogsService object with the same constructor structure as all other service proxy classes that I covered in the last post in the series then create an instance of BlogGroup object and set some properties for it. My service proxy class has an AddBlogGroup function that adds an instance of BlogGroup to the system and returns an instance of the same object for what is added. In the next step I use the returned object and call its Delete method to delete the blog group on fly.
Note that such a task can be done in a few ways with Community Server REST API that are identical behind the scenes but are presented in a good framework design for your convenient.
Also note that you’re not always compelled to create a new instance of the object and get the result of add functions. I just did that to clarify my sample code.
As the second common scenario, I want to create a blog on fly and add it to the system which is now much easier than before with Community Server REST API.
static void Main(string[] args)
{
Console.Title = "Community Server REST API - Blogs";
BlogsService service = new BlogsService("http://localhost/cs/", "admin", "2nw9q0ki");
Blog blog = new Blog();
blog.Name = "Keyvan Blog";
blog.Description = "A sample blog created by REST API.";
blog.BlogGroupId = 4;
blog.Key = "cs_api";
Blog newBlog = service.AddBlog(blog);
Console.WriteLine("New blog added.");
Console.WriteLine("New blog name: {0}", newBlog.Name);
Console.ReadLine();
}
After creating a BlogsService instance, I create a Blog object and set some required properties for it such as its name, description, group ID, and application key (that appears in the URL). The next obvious step is, using the AddBlog function to add this blog to the system.
The last sample that I discover is, adding a blog post to the system through REST API. In this case I follow the same approach to create the post and set its properties.
static void Main(string[] args)
{
Console.Title = "Community Server REST API - Blogs";
BlogsService service = new BlogsService("http://localhost/cs/", "admin", "2nw9q0ki");
Blog blog = service.GetBlog("cs_api");
BlogPost post = new BlogPost();
post.Title = "Sample Post";
post.Body = "<p>This post is added through REST API.</p>";
post.BlogId = blog.Id;
BlogPost newPost = service.AddBlogPost(post);
Console.WriteLine("New post added.");
Console.WriteLine("New post title: {0}", newPost.Title);
Console.ReadLine();
}
Here I follow the same workflow in my development, too. A Blog instance is retrieved to add the post to it then a BlogPost object is created with some basic properties, and AddBlogPost function adds this post to the system.

You see the simple workflow model in Community Server REST API when using the built-in service library. You can simply get this thread and extend it to other subsystems and scenarios with some modifications but the core is as simple as what I showed in this post.
Generally Community Server REST API accomplishes same goals as normal server development in less amount of code, and in a much simpler way which is a big advantage for it.
I would consider this post as my last post in this series because I don’t think there isn’t any point that deserves such a blog post to be discussed. I guess all main points are covered unless someone leaves a comment and notifies me about something that I’m missing. In the near future I want to publish new posts discussing more in-depth topics about Community Server development.
Dew Drop - November 18, 2008 | Alvin Ashcraft's Morning Dew
Nov 18, 2008 9:39 AM
#
Pingback from Dew Drop - November 18, 2008 | Alvin Ashcraft's Morning Dew
Chris
Nov 21, 2008 1:47 PM
#
Nice info Keyvan, thank you. Do you have some good examples to point out where the CS API is being used? In particular for integrating forums and comments in other site content.
Leave a Comment