Created
February 17, 2015 16:20
-
-
Save hagbarddenstore/3fea498e4f5871d86634 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Company | |
{ | |
using System; | |
public abstract class Handler | |
{ | |
public static implicit operator Handler(Action<ResponseWriter, Request> handler) | |
{ | |
return new HandlerWrapper(handler); | |
} | |
public abstract void Serve(ResponseWriter response, Request request); | |
private class HandlerWrapper : Handler | |
{ | |
private readonly Action<ResponseWriter, Request> _handler; | |
public HandlerWrapper(Action<ResponseWriter, Request> handler) | |
{ | |
if (handler == null) | |
{ | |
throw new ArgumentNullException("handler"); | |
} | |
_handler = handler; | |
} | |
public override void Serve(ResponseWriter response, Request request) | |
{ | |
_handler(response, request); | |
} | |
} | |
} | |
public class Router | |
{ | |
public Route Handle(string path, Handler handler) | |
{ | |
return null; | |
} | |
} | |
public class Program | |
{ | |
public static void Main(string[] arguments) | |
{ | |
var router = new Router(); | |
router.Handle("/api/v1/users", ListUsers).Methods(HttpMethods.Get); | |
Server.ListenAndServe(":8080", router); | |
} | |
private static void ListUsers(ResponseWriter response, Request request) | |
{ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment