Skip to content

Instantly share code, notes, and snippets.

@crjcodes
Created December 27, 2022 14:26
Show Gist options
  • Save crjcodes/1318f2cf1187410382537dc9fd3b3e60 to your computer and use it in GitHub Desktop.
Save crjcodes/1318f2cf1187410382537dc9fd3b3e60 to your computer and use it in GitHub Desktop.
Minimal API endpoints
// 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