示例#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
    public void Setup()
    {
        Express server = new Express();

        server.GET("/PlainText", (req, res) =>
        {
            res.Status(200).Send("Hello, World!");
        });

        server.GET("/Json", (req, res) =>
        {
            res.Status(200).Json(new { Id = 300 });
        });

        Thread listenThread = new Thread(() =>
        {
            server.Listen();
        });

        listenThread.Start();
    }