Skip to content

Instantly share code, notes, and snippets.

@abobija
Created November 16, 2019 14:22
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abobija/1ad006785db8b0411521ec7e242242a9 to your computer and use it in GitHub Desktop.
Save abobija/1ad006785db8b0411521ec7e242242a9 to your computer and use it in GitHub Desktop.
Code written in YouTube video https://youtu.be/eSS5w29iVl8
using SimpleHttp;
using System.Threading;
namespace SimpleHttpDemo
{
class Program
{
static void Main(string[] args)
{
Route.Add("/", (req, res, props) =>
{
res.AsText("Welcome to the Simple Http Server");
});
Route.Add("/users/{id}", (req, res, props) =>
{
res.AsText($"You have requested user #{props["id"]}");
}, "POST");
Route.Add("/header", (req, res, props) =>
{
res.AsText($"Value of my-header is: {req.Headers["my-header"]}");
});
HttpServer.ListenAsync(
1337,
CancellationToken.None,
Route.OnHttpRequestAsync
)
.Wait();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment