Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kathleenwest/minimalwebapipizzastoretutorialdemo
Quick steps and demo code to quickly create a minimal web api with asp.net core and swagger setup. This project code is the result of a Microsoft Learn tutorial to build a web API with minimal API, ASP.NET Core, and .NET.
https://github.com/kathleenwest/minimalwebapipizzastoretutorialdemo
asp-net-core crud demo how-to mapget mappost microsoft-learn minimal-api minimal-web-api pizza pizza-app quick quick-start step-by-step step-by-step-guide swagger swagger-ui tutorial web-api webapi
Last synced: 11 days ago
JSON representation
Quick steps and demo code to quickly create a minimal web api with asp.net core and swagger setup. This project code is the result of a Microsoft Learn tutorial to build a web API with minimal API, ASP.NET Core, and .NET.
- Host: GitHub
- URL: https://github.com/kathleenwest/minimalwebapipizzastoretutorialdemo
- Owner: kathleenwest
- Created: 2023-12-25T21:52:35.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-12-25T22:58:01.000Z (about 1 year ago)
- Last Synced: 2024-11-23T02:28:28.799Z (2 months ago)
- Topics: asp-net-core, crud, demo, how-to, mapget, mappost, microsoft-learn, minimal-api, minimal-web-api, pizza, pizza-app, quick, quick-start, step-by-step, step-by-step-guide, swagger, swagger-ui, tutorial, web-api, webapi
- Language: C#
- Homepage: https://portfolio.katiegirl.net/2023/12/25/minimal-web-api-with-asp-net-core-demo-and-quick-start/
- Size: 72.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# PizzaStoreMinimalWebApi
A minimal web api project to showcase basic CRUD operations with Http Verb Operations (Get, Post, Put, and Delete). Swagger documentation is configured for test and verification of the web api. See quick steps and demo code to quickly create a minimal web api with asp.net core and swagger setup. This project code is the result of a Microsoft Learn tutorial to build a web API with minimal API, ASP.NET Core, and .NET.
## How to Quickly Create a Minimal Web Api
### Step #1 - Create web app
```dotnet new web -o PizzaStore -f net8.0```### Step #2 - Add Routes to Program.cs
Just before app.Run(), add your routes to do stuff. Here is a simple example with a pizza route:
```
app.MapGet("/pizzas/{id}", (int id) => PizzaDB.GetPizza(id));
app.MapGet("/pizzas", () => PizzaDB.GetPizzas());
app.MapPost("/pizzas", (Pizza pizza) => PizzaDB.CreatePizza(pizza));
app.MapPut("/pizzas", (Pizza pizza) => PizzaDB.UpdatePizza(pizza));
app.MapDelete("/pizzas/{id}", (int id) => PizzaDB.RemovePizza(id));
```
### Step #3 - Add Swagger Documentation (Program.cs)
#### Install the Swashbuckle package
```dotnet add package Swashbuckle.AspNetCore --version 6.5.0```
#### Configure Builder Services
```
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "PizzaStore API", Description = "Making the Pizzas you love", Version = "v1" });
});
```
#### Configure the app
```
// Change configurations based on environmental settings
// HINT: See Project Properties --> Debug --> Launch Profiles --> Select
// Add ASPNETCORE_ENVIRONMENT = "Development"
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "PizzaStore API V1");
});
}
```
## Demo Picture
![Swagger Demo](/images/swagger.jpg)
## ReferencesThis code is the result of a Microsoft Learn tutorial project: [Build a web API with minimal API, ASP.NET Core, and .NET](https://learn.microsoft.com/en-us/training/modules/build-web-api-minimal-api/)