Created
November 16, 2019 14:22
-
-
Save abobija/1ad006785db8b0411521ec7e242242a9 to your computer and use it in GitHub Desktop.
Code written in YouTube video https://youtu.be/eSS5w29iVl8
This file contains hidden or 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
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