Grapevine 5.0 Beta 0

Scott Offen

Scott Offen

Grapevine Creator

The first beta version of Grapevine 5.0 was uploaded to NuGet.org today, December 25, 2020.

A Complete Rewrite#

A huge thank you to everyone who has downloaded and used Grapevine over the years, and especially those who have provided feedback and code to make the project better.

That said, Grapevine 5 is a complete rewrite from top to bottom. The primary goal has always been that it must be simple to implement, without compromising on functionality or performance. The new Grapevine 5 is async from the receipt of the request to the sending of the response, which makes it blazing fast. It has a cleaner and more flexible logging mechanism, and supports dependency injection in routes. It can be easily extended to meet specific needs, and you can even wholesale replace any part with your own implementation.

Things To Know#

A new major version naturally brings with it breaking changes. In the case of Grapevine 5, it (as Jonathan Coulton might say) breaks everything in the nicest way.

If you have used a previous version of Grapevine, here is a quick summary of some thing you should know going in, in no particular order.

  • Target Frameworks: netstandard2.0, netstandard 2.1, and net5.0
  • Symbols package is also up on NuGet, for easier debugging during development
  • I've removed the Grapevine.Client, at least for now (recommend using IHttpClientFactory)
  • The single URI restriction has been removed, so you can listen on multiple ports!
  • Everything you need in the library is now in the Grapevine namespace
  • Grapevine is async all the way through the stack
  • This beta does not contain an IContentFolder (formerly IPublicFolder) implementation
  • There are built in extension for adding CORS (IRestServer.UseCorsPolicy()) and correlation ids (IRestServer.UseCorrelationId())
  • Standards based dependency injection (using Microsoft.Extensions.DependencyInjection) and logging (using Microsoft.Extensions.Logging)
  • RestResource attributed classes are no longer required to have parameterless constructor (see above)

Code Sample#

warning

The RestServer.DeveloperConfiguration extension method used on line 12 is only available in this beta. It will be replaced with more elegant solution for start up and configuration.

Program.cs
using System;
using System.Linq;
using Grapevine;
namespace MyConsoleApp
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Starting Grapevine Server");
using (var server = RestServer.DeveloperConfiguration((services) =>
{
// If your resources need dependencies injected, register those classes here
}, true))
{
Console.WriteLine($"Server will listen on {string.Join(", ", server.Prefixes)}");
server.Start();
Console.WriteLine("Press any key to stop the sample server.");
Console.ReadLine();
}
}
}
}

Of course, you'll need some routes to go along with that...

MyResource.cs
using System.Threading.Tasks;
using Grapevine;
using Microsoft.Extensions.Logging;
namespace MyConsoleApp
{
[RestResource]
public class MyResource
{
private readonly ILogger<MyResource> _logger;
public MyResource(ILogger<MyResource> logger)
{
_logger = logger;
}
[RestRoute("Get", "/hello", Name = "Test Route", Description = "Just a route to test stuff with.", Enabled = true)]
public async Task HelloWorld(IHttpContext context)
{
await context.Response.SendResponseAsync("Hello, world!");
}
[RestRoute]
public async Task CathcAll(IHttpContext context)
{
_logger.LogTrace($"{context.Request.HttpMethod} {context.Request.PathInfo} : Catch All Method");
await context.Response.SendResponseAsync(HttpStatusCode.Ok);
}
}
}