From 018e82afc90afbcac64268939c3698746e26af5f Mon Sep 17 00:00:00 2001 From: Egidijus Lileika Date: Tue, 9 Feb 2021 12:05:21 +0200 Subject: [PATCH] Updated readme --- README.md | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 70fbdc2..01f2768 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ namespace CuipodExample { class Server { - static void Main(string[] args) + static int Main(string[] args) { App app = new App( "/", // directory to serve @@ -22,28 +22,53 @@ namespace CuipodExample ); // Serve files - app.OnRequest("/", response => { + app.OnRequest("/", (request, response) => { response.RenderFileContent("index.gmi"); }); - app.OnRequest("/about/", response => { - response.RenderFileContent("about_me.gmi"); + // Input example + app.OnRequest("/input", (request, response) => { + if (request.Parameters == null) + { + response.SetInputHint("Please enter something: "); + response.Status = StatusCode.Input; + } + else + { + // redirect to show/ route with input parameters + response.SetRedirectURL(request.BaseURL + "/show?" + request.Parameters); + response.Status = StatusCode.RedirectTemp; + } + }); + + app.OnRequest("/show", (request, response) => { + if (request.Parameters == null) + { + // redirect to input + response.SetRedirectURL(request.BaseURL + "/input"); + response.Status = StatusCode.RedirectTemp; + } + else + { + // show what has been entered + response.RenderPlainTextLine("# " + request.Parameters); + } }); // Or dynamically render content - app.OnRequest("/dynamic/content/", response => { + app.OnRequest("/dynamic/content", (request, response) => { response.RenderPlainTextLine("# woah much content!"); response.RenderPlainTextLine("More utilities to render content will come soon!"); }); // Optional but nice. In case it is specified and client will do a bad route // request we will respond with Success status and render result from this lambda - app.OnBadRequest(response => { + app.OnBadRequest((request, response) => { response.RenderPlainTextLine("# Ohh No!!! Request is bad :("); }); - app.Run(); + return app.Run(); } } } -``` \ No newline at end of file +```