scottoffen / grapevine

Fast, unopinionated, embeddable, minimalist web framework for .NET
https://scottoffen.github.io/grapevine/
MIT License
103 stars 16 forks source link
csharp embeddable grapevine httpclient httplistener rest rest-api rest-framework rest-server rest-service rest-services restapi restful restful-api restful-webservices

Grapevine

Grapevine is a fast, unopinionated, embeddable, minimalist web framework for .NET. Grapevine is not intended to be a replacement for IIS or ASP.NET, but rather to function as an embedded REST/HTTP server in non-ASP.NET projects.

Installation

Grapevine is available on NuGet.org and can be installed using a NuGet package manager or the .NET CLI.

Powershell:

Install-Package Grapevine -Version 5.0.0-rc.10

.NET CLI

> dotnet add package Grapevine --version 5.0.0-rc.10

Usage

Grapevine is easy to get started with.

Create a simple route. This is the code that you want to run when a request comes in using the specified HTTP verb and path. Route methods must be asynchronous!

[RestResource]
public class MyResource
{
    [RestRoute("Get", "/api/test")]
    public async Task Test(IHttpContext context)
    {
        await context.Response.SendResponseAsync("Successfully hit the test route!");
    }
}

Next, create your first server using provided defaults (it's recommended to use the RestServerBuilder class to do this) and start it up!

using (var server = RestServerBuilder.UseDefaults().Build())
{
    server.Start();

    Console.WriteLine("Press enter to stop the server");
    Console.ReadLine();
}

Open your preferred browser and go to http://localhost:1234/api/test. You should see the following output in your browser:

Successfully hit the test route!

You'll see a lot of output in the console as well, because the defaults inject a console logger with the minimum level set to trace.

Support

Contributing

We welcome contributions from the community! In order to ensure the best experience for everyone, before creating an issue or submitting a pull request, please see the contributing guidelines and the code of conduct. Failure to adhere to these guidelines can result in significant delays in getting your contributions included in the project.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

License

Grapevine 5 is licensed under the MIT license.

Using Grapevine? We'd Love To Hear About It!

Few thing are as satisfying as hearing that your open source project is being used and appreciated by others. (Except for a nice MLT – mutton, lettuce and tomato sandwich, where the mutton is nice and lean and the tomato is ripe. They're so perky, I love that.) Jump over to the discussion boards and share the love!