예제 #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.Run(async(context) =>
            {
                if (context.Request.Query.ContainsKey("word"))
                {
                    string word = context.Request.Query["word"];
                    Models.Dictionary dictionary = Dictionary("Models/Dictionary.txt");
                    string translatedWord        = dictionary.findTranslation(word);
                    if (translatedWord == null)
                    {
                        context.Response.StatusCode = 404;
                        await context.Response.WriteAsync("Not Found");
                    }
                    else
                    {
                        context.Response.ContentType = "text/plain;charset=utf-8";
                        await context.Response.WriteAsync($"{word} = {translatedWord}");
                    }
                }
                else
                {
                    context.Response.StatusCode = 400;
                    await context.Response.WriteAsync("Bad Request");
                }
            });
        }