Skip to content

Commit

Permalink
Simplify some things (#2)
Browse files Browse the repository at this point in the history
- Remove AddControllers/MapControllers
- Remove UseAuthorization
- Remove Results.Ok since we're just returning the objects directly
- Move middleware first, this is purely a style preference
  • Loading branch information
davidfowl authored Aug 31, 2021
1 parent b08e71d commit f3db20a
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions samples/HaveIBeenPwned.MinimalApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
builder.Services.AddPwnedServices(
builder.Configuration.GetSection(nameof(HibpOptions)));

builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(options =>
options.SwaggerDoc("v1", new() { Title = "HaveIBeenPwned.MinimalApi", Version = "v1" }));
Expand All @@ -23,35 +22,33 @@
options.SwaggerEndpoint("/swagger/v1/swagger.json", "HaveIBeenPwned.MinimalApi v1"));
}

app.UseHttpsRedirection();

// "Have I Been Pwned" Breaches API
app.MapGet("api/breaches/{breachName}",
async (string breachName, IPwnedBreachesClient client) =>
Results.Ok(await client.GetBreachAsync(breachName)));
await client.GetBreachAsync(breachName));
app.MapGet("api/breaches/headers/{domain}",
async (string? domain, IPwnedBreachesClient client) =>
Results.Ok(await client.GetBreachAsync(domain!)));
await client.GetBreachAsync(domain!));
app.MapGet("api/breaches/{account}/breaches",
async (string account, IPwnedBreachesClient client) =>
Results.Ok(await client.GetBreachesForAccountAsync(account)));
await client.GetBreachesForAccountAsync(account));
app.MapGet("api/breaches/{account}/headers",
async (string account, IPwnedBreachesClient client) =>
Results.Ok(await client.GetBreachHeadersForAccountAsync(account)));
await client.GetBreachHeadersForAccountAsync(account));
app.MapGet("api/breaches/dataclasses",
async (IPwnedBreachesClient client) =>
Results.Ok(await client.GetDataClassesAsync()));
await client.GetDataClassesAsync());

// "Have I Been Pwned" Pwned Passwords API
app.MapGet("api/passwords/{plainTextPassword}",
async (string plainTextPassword, IPwnedPasswordsClient client) =>
Results.Ok(await client.GetPwnedPasswordAsync(plainTextPassword)));
await client.GetPwnedPasswordAsync(plainTextPassword));

// "Have I Been Pwned" Pwned Pastes API
app.MapGet("api/pastes/{account}",
async (string account, IPwnedPastesClient client) =>
Results.Ok(await client.GetPastesAsync(account)));

app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
await client.GetPastesAsync(account));

await app.RunAsync();

0 comments on commit f3db20a

Please sign in to comment.