Doing some fixup
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using Tesses;
|
||||
using System.Drawing;
|
||||
using Tesses;
|
||||
using Tesses.WebServer;
|
||||
using Tesses.WebServer.HtmlLayout;
|
||||
namespace Tesses.WebServer.ConsoleApp
|
||||
{
|
||||
class JsonObj
|
||||
@@ -8,10 +10,60 @@ namespace Tesses.WebServer.ConsoleApp
|
||||
|
||||
public DateTime Birthday {get;set;}=DateTime.Now;
|
||||
}
|
||||
public class MyOther
|
||||
{
|
||||
[FormNewLine]
|
||||
|
||||
public string Hello {get;set;}="";
|
||||
[FormNewLine]
|
||||
|
||||
public Color FavoriteColor {get;set;}=Color.Pink;
|
||||
// [FormNewLine]
|
||||
|
||||
//public HttpFileResponseEntry[] Files {get;set;}=new HttpFileResponseEntry[0];
|
||||
}
|
||||
public enum TestEnum
|
||||
{
|
||||
Apple,
|
||||
Orange,
|
||||
Grape,
|
||||
Banana,
|
||||
Raspberry,
|
||||
|
||||
Blueberry,
|
||||
Strawberry
|
||||
}
|
||||
class Test
|
||||
{
|
||||
[FormNewLine]
|
||||
[FormText("Your Name",Placeholder="Name",Name="name")]
|
||||
public string Name {get;set;}="";
|
||||
[FormNewLine]
|
||||
[FormText("Describe yourself",Placeholder="Description",Name="description")]
|
||||
public string Description {get;set;}="";
|
||||
[FormNewLine]
|
||||
[FormCheckbox("Are you an adult")]
|
||||
public bool Adult {get;set;}=false;
|
||||
[FormNewLine]
|
||||
[FormCheckbox("Email Me")]
|
||||
public bool EmailMe {get;set;}=true;
|
||||
|
||||
[FormNewLine]
|
||||
[FormRadio("fruit")]
|
||||
public TestEnum Fruit {get;set;}=TestEnum.Raspberry;
|
||||
|
||||
[FormNewLine]
|
||||
[FormFieldSet]
|
||||
public MyOther MyOther {get;set;}=new MyOther();
|
||||
|
||||
|
||||
}
|
||||
|
||||
class MainClass
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
|
||||
TestObject some_object = new TestObject();
|
||||
RouteServer rserver = new RouteServer();
|
||||
rserver.Add("/", async(ctx) => {
|
||||
@@ -20,6 +72,43 @@ namespace Tesses.WebServer.ConsoleApp
|
||||
rserver.Add("/page", async(ctx) => {
|
||||
await ctx.SendTextAsync("Demetria Devonne Lovato 8/20/1992");
|
||||
});
|
||||
rserver.Add("/john",async(ctx)=>{
|
||||
Test other = new Test();
|
||||
ctx.ParseSmartForm(other);
|
||||
|
||||
await ctx.SendJsonAsync(other);
|
||||
},"POST");
|
||||
rserver.Add("/html_ex",async(ctx)=>{await ctx.SendHtmlAsync(H.Html(
|
||||
H.Head(
|
||||
H.Meta().WithAttribute("charset","UTF-8"),
|
||||
H.Meta().WithAttribute("name","viewport").WithAttribute("content","width=device-width, initial-scale=1.0"),
|
||||
H.Title("Document")
|
||||
),
|
||||
H.Body(H.Form("./john",new Test(),true))
|
||||
).WithAttribute("lang","en"));});
|
||||
rserver.Add("/absolute_paths",(ctx)=>{
|
||||
using(var sw = ctx.GetResponseStreamWriter())
|
||||
{
|
||||
sw.WriteLine($"Root: {ctx.GetRealRootUrl()}");
|
||||
sw.WriteLine($"Current Server Root: {ctx.GetCurrentServerPath()}");
|
||||
sw.WriteLine($"Demetria: {ctx.GetRealUrlRelativeToCurrentServer("/page")}");
|
||||
sw.WriteLine($"Headers: {ctx.GetRealUrlRelativeToCurrentServer("/headers")}");
|
||||
sw.WriteLine($"Relative To Root: {ctx.GetRealUrl("/johnconnor/")}");
|
||||
}
|
||||
});
|
||||
|
||||
rserver.Add("/headers",(ctx)=>{
|
||||
using(var sw = ctx.GetResponseStreamWriter())
|
||||
{
|
||||
foreach(var item in ctx.RequestHeaders)
|
||||
{
|
||||
foreach(var item2 in item.Value)
|
||||
{
|
||||
sw.WriteLine($"{item.Key}: {item2}");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
rserver.Add("/jsonEndpoint",async(ctx)=>{
|
||||
var res=await ctx.ReadJsonAsync<JsonObj>();
|
||||
|
||||
Reference in New Issue
Block a user