Introducing : Grapevine, A C# REST Server Class Library

Grapevine is .NET 4.0 class library I wrote in C# to provide my applications with an easy way to include a REST server without a dependency on ASP.NET.  While I was at it, I made it a simple HTTP server at the same time.  And added the ability to be a REST client, too.  All that, in one simple class library.

Version 2.7.1 has been stable for over two weeks, and is working like a champ in our Mercenary .NET project, so I felt it was ready to introduce to a wider audience. (Even though I’ve teased at it in several previous blog posts.)

Setting Expectations

Before I get too far, let’s get some expectations correct.

  1. Grapevine is not intended to be a replacement for Microsoft IIS or Apache HTTP Server.  Instead, Grapevine aims to be embedded in your application, where using one of those would be impossible, or just plain overkill.
  2. Grapevine does not do any script parsing (PHP, Perl, Python, Ruby, etc.) by default – but feel free to fork this project and hack away! I’m pretty sure it could be done, I just haven’t encountered a need for it (yet).
  3.  A single instance of a class that extends RestServer will only listen on one host/port combination (however, you may define the host as “*”).
  4.  You will likely be required to open a port in your firewall for remote computers to be able to send requests to your application. Grapevine will not automatically do that for you. You might want to do that during the installation of your application.

Nothing here you can’t get off the of projects home page on GitHub.

Getting Started

You can download Grapevine directly from NuGet, and the wiki attached to the project on GitHub has some great Getting Started guides that will walk you through the basics.

All the examples are in C#, but feel free to port them to your .NET language of choice.

Why Build a C# REST Server, Anyway?

A quick Google search will reveal some good links on how to build a REST server in C#.

The same Google search will also reveal that a lot of people are asking the question “How do I build a REST server in C#?”, and there does not seem to be any kind of authoritative solution.

Most people don’t actually want to build a REST server from scratch. I know I didn’t, but there wasn’t a solution out there that I could just plug into my project and start using.  So I created one.

So I never have to build it again.

Build a c-sharp rest server so that I ever have to do it again.
Miyagi: Then why train? Daniel: So I won’t have to fight.

Miyagi have hope for you.

Why Bundle A REST Server With a Client?

Suppose your application is deployed across multiple nodes on the network. If they use REST services to communicate, it means not only do they need to be able to respond to REST requests sent to them, but they need to be able to send requests to other nodes.

The model we are using in Mercenary is similar (at a very high level) to Selenium, where nodes (we call them targets) register with a hub (we call ours a server), and the hub dishes out work for the nodes to do.

The patterns are similar, having them in the same package just made sense.  One class library, two purposes.

A way better transformer than this!
A way better transformer than this!

What About JSON Support?

Am I cramming in too much jargon here, or is someone playing buzzword bingo?

Buzzword Overkill!

It’s so easy to extend Grapevine to send/receive JSON payloads, that I show you how in one of the getting started guides.

Initial version of Grapevine did this out-of-the-box, but it required additional dependencies, and I figured you might want to be the one that determined which JSON parsing library you used.  Freedom!

Keep Calm and Use Grapevine

So, this Memorial Day weekend, when you find yourself in need of a lightweight, easy to use and super awesome REST server for your .NET project, give Grapevine a go!

2 thoughts on “Introducing : Grapevine, A C# REST Server Class Library”

  1. Really nice REST system, have started using it in an old project of mine that i am revamping.

    I have the embedded rest server in my application, i can retrieve a JSON string from it by using JsonConvert to serialise an object to json.

    What i’m wondering however (and the wiki didn’t really point this out) is how do i set it up so that a front end (such as a website with jquery) can send a json payload back to the REST server to be turned into an object?

Leave a Reply

Your email address will not be published. Required fields are marked *