Tag Archives: routing

Minimal API | Route Handler için Response çeşitleri

Minimal API içerisinde bir route handler’dan döndürülebilecek response çeşitlerini ele aldık bu videoda.

✅Github reposu: https://github.com/sonergonul/MinimalAPI

Response çeşitleri şu şekilde;

➡️ IResult – Task<IResult> veya ValueTask<IResult>

➡️ string – Task<string> veya ValueTask<string> – text/plain

➡️ T – Json seralize – application/json

🟢 app.MapGet("/response1", () lambda "Hello World");

🟢 app.MapGet("/response2", () => new { Message = "Hello World" });

🟢 app.MapGet("/response3", () => Results.Ok(new { Message = "Hello World" }));

🟢 app.MapGet("/response4", () => Results.Json(new { Message = "Hello World" }));

🟢 app.MapGet("/405", () => Results.StatusCode(405));

🟢 app.MapGet("/text", () => Results.Text("This is some text"));

🟢 app.MapGet("/old-path", () => Results.Redirect("/new-path"));

🟢 app.MapGet("/download", () => Results.File("C:/appsettings.json", contentType: "application/json", fileDownloadName: "appsettings.json"));