Created
December 27, 2022 14:26
-
-
Save crjcodes/1318f2cf1187410382537dc9fd3b3e60 to your computer and use it in GitHub Desktop.
Minimal API endpoints
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In the real world, this would be coming from a service -- data access, dbContext, or repo, etc | |
var records = builder.Configuration.GetSection("LabRecords").Get<List<FlattenedLabRecord>>(); | |
// API ROUTING | |
app.MapGet("/", () => { return records; }); | |
app.MapGet("/LabRecords", () => { return records; }) | |
.WithOpenApi(); | |
app.MapGet("/LabNames", () => { return records?.Select(r => r.Name).Distinct(); }) | |
.WithOpenApi(); | |
app.MapGet("/LabRecords/Search", (string LabName) => | |
{ | |
return records?.Where(r => r.Name.ToUpper() == LabName.ToUpper()); | |
}) | |
.WithOpenApi(); | |
// REFERENCE | |
// If a need exists to bind complex parameters, see https://code-maze.com/aspnetcore-query-string-parameters-minimal-apis/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment