In the code below I am waiting for any call to the 8080 port.
public static void Main()
{
HttpListener listener = new HttpListener();
listener.Prefixes.Add("http://*:8080/");
listener.Start();
while(isRunning)
{
HttpListenerContext ctx = listener.GetContext();
new Thread(new Worker(ctx).ProcessRequest).Start();
}
}
Is it possible to map specific URL patterns to different behavior? I want achieve a REST-style server i.e. a call to localhost:8080/person/1 will launch getPersonHandler(int)
[Mapping("*:8080/person/$id")]
public void getPersonHandler(int id)
{
// ...
}
The Mapping syntax is just my wishful analogy to JAX-RS libraries that I know. I would like to do the same in C# (desktop C#, not asp).
You can get a similar effect without attributes
Usage would be:
if you really want to use Attributes then
Then you can use as
http://localhost:8080/Person/333and your definitions would be