コード例 #1
0
        static void Main(string[] args)
        {
            Express server = new Express();

            server.Use(BodyParser.Json);

            server.Use((req, res, next) =>
            {
                string authentication = req.Header["Authorization"];
                if (authentication == null)
                {
                    res.Status(401).Send("Unauthorized");
                    return;
                }
                else
                {
                    //Magic token checking magic here
                    next();
                }
            });

            server.GET("/", (req, res) =>
            {
                if (req.Body == null)
                {
                    res.Status(400).Send("Expected body");
                    return;
                }
                User user = req.ToType <User>();

                res.Send($"{user.Id} {user.Name}");
            });

            server.Listen();
        }
コード例 #2
0
ファイル: Global.asax.cs プロジェクト: speier/expressnet
        protected virtual void Application_Start(Object sender, EventArgs e)
        {
            var app = new Express ();

            app.Use (PoweredByExpressNet ());

            app.Get ("/", (req, res) => {
                res.Send ("hello world");
            });

            app.Get ("/json", (req, res) => {
                res.Send (new { name = "Express.NET", type = "Experiment" });
            });

            app.Get ("/user/{id}", LoadUser (), (req, res) => {
                var user = req["user"];
                res.Send (user);
            });
        }