5 Days of Simple.Web: Getting Started

Getting started

Simple.Web is intended to be exactly that – Simple! Let’s see how easy it is to get started.

1. Create a new Console Project

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.

2. Install NuGet packages

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.

3. Bootstrap

Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
namespace GettingStarted
{
  using System;

  internal class MainClass
  {
    private static void Main (string[] args)
    {
      new Simple.Web.Hosting.Self.OwinSelfHost().Run();
    }
  }
}

4. Create a resource

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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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; }
  }
}

5. Run & Browse

Let’s hit F5/CMD-Enter to run and browse to the default address of http://localhost:3333.

Too Simple? Bit disappointed? Sorry about that ;–)

Comments