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.)
Before I get too far, let’s get some expectations correct.
- 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.
- 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).
- A single instance of a class that extends RestServer will only listen on one host/port combination (however, you may define the host as “*”).
- 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.
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.
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.
What About JSON Support?
Am I cramming in too much jargon here, or is someone playing buzzword bingo?
It’s so easy to extend Grapevine to send/receive JSON payloads, that I show you how in one of the getting started guides.
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!