-
Notifications
You must be signed in to change notification settings - Fork 66
Getting Started
Simple.Web is intended to be exactly that - Simple! Let's see how easy it is to get started.
Let's create a console project to bootstrap our example. I'm using MonoDevelop here to show Simple.Web is just as fantastic on Mono as .NET. If you also want to use MonoDevelop then I'd recommend installing the NuGet add-in.
I'm going to pick the new self-hosting package, it will bring in all the dependencies I need.
Note: As Katana v2 is only available as a pre-release package Simple.Web.Hosting.Self depends on a custom NuGet source; furthermore a custom RTM build of 'dev' branch ensuring mono-compatibility. To use Simple.Web.Hosting.Self add https://www.myget.org/F/katana-mono to your available package sources.
// Program.cs
namespace GettingStarted
{
using System;
internal class MainClass
{
private static void Main (string[] args)
{
new Simple.Web.Hosting.Self.OwinSelfHost().Run();
}
}
}
For the sake of simplicity I have chosen not to return a model (and thus use content negotiation) and instead inherit Simple.Web "OutputBehaviour" IOutput<RawHtml>
that will simple render the contents of the string into the response stream; together with a 200 OK HTTP response code we're done!
// GetIndex.cs
namespace GettingStarted
{
using System;
using Simple.Web;
using Simple.Web.Behaviors;
[UriTemplate("/")]
public class GetIndex : IGet, IOutput<RawHtml>
{
public Status Get ()
{
this.Output = "<h1>Hello from Simple.Web!</h1>";
return 200;
}
public RawHtml Output { get; set; }
}
}
Let's hit F5/CMD-Enter to run and browse to the default address of http://localhost:3333.