Skip to content

Commit e334b21

Browse files
authored
Merge pull request dotnet#80 from sammychinedu2ky/multipleresultypes
2 parents e6e2fdc + 552819d commit e334b21

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net7.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.0-preview.7.22376.6" />
11+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
12+
</ItemGroup>
13+
14+
</Project>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using Microsoft.AspNetCore.Http.HttpResults;
2+
using Microsoft.AspNetCore.OpenApi;
3+
4+
var builder = WebApplication.CreateBuilder(args);
5+
6+
// Add services to the container.
7+
builder.Services.AddSingleton<List<Book>>((sp) =>
8+
{
9+
return new(){
10+
new Book(1, "Testing Dot", "John Doe"),
11+
new Book(2, "Learn Linq", "Rick Perry"),
12+
new Book(3, "Generics", "Dalis Chevy"),
13+
new Book(4, "Testing the Mic", "Bob Tik"),
14+
new Book(5, "Drop the Dot", "Farmy Lix"),
15+
};
16+
});
17+
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
18+
builder.Services.AddEndpointsApiExplorer();
19+
builder.Services.AddSwaggerGen();
20+
21+
var app = builder.Build();
22+
23+
// Configure the HTTP request pipeline.
24+
if (app.Environment.IsDevelopment())
25+
{
26+
app.UseSwagger();
27+
app.UseSwaggerUI();
28+
}
29+
30+
app.UseHttpsRedirection();
31+
32+
app.MapGet("/book{id}", Results<Ok<Book>, NotFound> (int id, List<Book> bookList) =>
33+
{
34+
return bookList.FirstOrDefault((i) => i.Id == id) is Book book
35+
? TypedResults.Ok(book)
36+
: TypedResults.NotFound();
37+
});
38+
39+
app.Run();
40+
record Book(int Id, string Title, string Author);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
}
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
},
8+
"AllowedHosts": "*"
9+
}

0 commit comments

Comments
 (0)