### Product Endpoints (GET, POST, DELETE) Source: https://context7.com/mariogk/terrascale.minimalendpoints/llms.txt Demonstrates the use of `BaseMinimalApiEndpoint` helper methods for common HTTP operations like getting, creating, and deleting products. ```APIDOC ## Product Endpoints ### GET /api/products/{id} #### Description Retrieves a specific product by its ID. #### Method GET #### Endpoint /api/products/{id} #### Parameters ##### Path Parameters - **id** (int) - Required - The ID of the product to retrieve. #### Response ##### Success Response (200) - **product** (Product) - The requested product object. ##### Error Response (400) Invalid ID provided. ##### Error Response (404) Product not found. ### POST /api/products #### Description Creates a new product. #### Method POST #### Endpoint /api/products #### Parameters ##### Request Body - **request** (ProductRequest) - Required - An object containing the name of the product to create. #### Response ##### Success Response (201 Created) - **product** (Product) - The newly created product object, including its assigned ID. ### DELETE /api/products/{id} #### Description Deletes a specific product by its ID. #### Method DELETE #### Endpoint /api/products/{id} #### Parameters ##### Path Parameters - **id** (int) - Required - The ID of the product to delete. #### Response ##### Success Response (204 No Content) Indicates the product was successfully deleted. ### Request Body Example (POST) ```json { "name": "New Gadget" } ``` ### Response Example (GET 200) ```json { "id": 1, "name": "Existing Product" } ``` ### Response Example (POST 201 Created) ```json { "id": 1, "name": "New Gadget" } ``` ### Available Helper Methods - `Ok()`, `Ok(value)` - `Created(uri, value)`, `Created(uri, value)` - `NotFound()`, `NotFound(value)` - `BadRequest()`, `BadRequest(error)` - `Unauthorized()`, `Forbid()` - `NoContent()` - `Problem(detail, instance, statusCode, title, type, extensions)` ``` -------------------------------- ### Implement GET Endpoint with Query Parameter Binding (C#) Source: https://context7.com/mariogk/terrascale.minimalendpoints/llms.txt Illustrates how to create a GET endpoint that accepts query parameters for filtering or searching. The example demonstrates binding a 'city' query parameter to a string argument. Dependencies include Microsoft.AspNetCore.Mvc and TerraScale.MinimalEndpoints. ```csharp using Microsoft.AspNetCore.Mvc; using TerraScale.MinimalEndpoints.Attributes; namespace TerraScale.MinimalEndpoints.Example.Endpoints; [MinimalEndpoints("api/weather")] [EndpointGroupName("Weather API")] public class WeatherEndpoints : BaseMinimalApiEndpoint { /// /// Gets weather information for a city /// /// The city name to get weather for /// Weather information for the specified city /// /// This endpoint provides a simple weather forecast. /// Currently returns a static sunny weather for all cities. /// /// Weather information retrieved successfully /// Invalid city name provided [HttpGet] [Produces("application/json", "text/plain")] public async Task GetWeather([FromQuery] string city) { await Task.Delay(1); return $"Weather in {city} is Sunny"; } } // Request: GET /api/weather?city=Boston // Response: "Weather in Boston is Sunny" ``` -------------------------------- ### User Creation Endpoint Example Source: https://github.com/mariogk/terrascale.minimalendpoints/blob/main/README.md Example of defining a user creation endpoint using BaseMinimalApiEndpoint, including request body and service injection. ```APIDOC ## POST /api/v1/users ### Description Creates a new user. ### Method POST ### Endpoint /api/v1/users #### Request Body - **request** (CreateUserRequest) - Required - The user data to create. ### Request Example ```json { "name": "John Doe", "email": "john.doe@example.com" } ``` #### Success Response (201) - **User** (User) - The created user object. #### Response Example ```json { "id": "123e4567-e89b-12d3-a456-426614174000", "name": "John Doe", "email": "john.doe@example.com" } ``` ``` -------------------------------- ### Weather Information Endpoint Example Source: https://github.com/mariogk/terrascale.minimalendpoints/blob/main/README.md Example of defining an endpoint to retrieve weather information with OpenAPI metadata. ```APIDOC ## GET /api/weather ### Description Retrieves weather information. ### Method GET ### Endpoint /api/weather #### Success Response (200) - **WeatherForecast** (WeatherForecast) - Returns weather data. #### Response Example ```json { "date": "2023-10-27T10:00:00Z", "temperatureC": 20, "summary": "Chilly" } ``` ``` -------------------------------- ### Example ASP.NET Core Minimal API Endpoint with XML Documentation (C#) Source: https://github.com/mariogk/terrascale.minimalendpoints/blob/main/README.md Illustrates an example of a `GetWeatherEndpoint` using TerraScale.MinimalEndpoints, inheriting from `BaseMinimalApiEndpoint`. It includes standard HTTP attributes like `[HttpGet]` and `[Produces]`, along with XML documentation comments (``, ``) that the source generator uses to populate OpenAPI metadata. ```csharp [MinimalEndpoints("api/weather")] public class GetWeatherEndpoint : BaseMinimalApiEndpoint { /// /// Gets weather information /// /// Returns weather data [HttpGet] [Produces("application/json")] public async Task Handle() { // ... } } ``` -------------------------------- ### Program.cs Registration Source: https://github.com/mariogk/terrascale.minimalendpoints/blob/main/README.md Example of how to register Minimal Endpoints services and map endpoints in Program.cs. ```APIDOC ## Program.cs Configuration ### Description Demonstrates the minimal setup required in Program.cs to enable TerraScale.MinimalEndpoints. ### Code ```csharp var builder = WebApplication.CreateBuilder(args); // Add application services builder.Services.AddScoped(); // Register Minimal Endpoints services (automatically registers all endpoint classes) builder.Services.AddMinimalEndpoints(); var app = builder.Build(); // Map Minimal Endpoints routes app.MapMinimalEndpoints(); app.Run(); ``` ``` -------------------------------- ### Utilize BaseMinimalApiEndpoint Helper Methods for Responses (C#) Source: https://context7.com/mariogk/terrascale.minimalendpoints/llms.txt Demonstrates the use of built-in helper methods provided by BaseMinimalApiEndpoint to generate consistent HTTP responses. Examples include Ok, NotFound, BadRequest, Created, and NoContent for various scenarios like fetching, creating, or deleting products. Dependencies include TerraScale.MinimalEndpoints and Microsoft.AspNetCore.Mvc. ```csharp using TerraScale.MinimalEndpoints; using TerraScale.MinimalEndpoints.Attributes; using Microsoft.AspNetCore.Mvc; namespace MyApp.Endpoints; [MinimalEndpoints("api/products")] public class ProductEndpoint : BaseMinimalApiEndpoint { [HttpGet("{id}")] public async Task GetProduct([FromRoute] int id) { if (id <= 0) return BadRequest(new { error = "Invalid ID" }); var product = await FetchProductAsync(id); if (product == null) return NotFound(); return Ok(product); } [HttpPost] public async Task CreateProduct([FromBody] ProductRequest request) { var product = await SaveProductAsync(request); return Created($"/api/products/{product.Id}", product); } [HttpDelete("{id}")] public async Task DeleteProduct([FromRoute] int id) { await DeleteProductAsync(id); return NoContent(); } private async Task FetchProductAsync(int id) => await Task.FromResult(null); private async Task SaveProductAsync(ProductRequest request) => await Task.FromResult(new Product(1, request.Name)); private async Task DeleteProductAsync(int id) => await Task.CompletedTask; } public record Product(int Id, string Name); public record ProductRequest(string Name); // Available helper methods: // - Ok(), Ok(value) // - Created(uri, value), Created(uri, value) // - NotFound(), NotFound(value) // - BadRequest(), BadRequest(error) // - Unauthorized(), Forbid() // - NoContent() // - Problem(detail, instance, statusCode, title, type, extensions) ``` -------------------------------- ### GET /api/users/{id} Source: https://context7.com/mariogk/terrascale.minimalendpoints/llms.txt Retrieve a user resource by its ID using route parameter binding and dependency injection. This endpoint demonstrates how to define a GET request that accepts a path parameter. ```APIDOC ## GET /api/users/{id} ### Description Retrieve a specific user by their unique identifier. This endpoint utilizes route parameters to specify the user ID and injects a service to fetch the user data. ### Method GET ### Endpoint /api/users/{id} ### Parameters #### Path Parameters - **id** (int) - Required - The unique identifier of the user to retrieve. #### Query Parameters N/A #### Request Body N/A ### Request Example `GET /api/users/42` ### Response #### Success Response (200) - **User?** (object) - The user object if found, otherwise null. Contains 'id' (int) and 'name' (string). #### Response Example ```json { "id": 42, "name": "John Doe" } ``` Or ```json null ``` ``` -------------------------------- ### GET Endpoint with Route Parameters and Service Injection Source: https://context7.com/mariogk/terrascale.minimalendpoints/llms.txt This C# code defines a GET endpoint for retrieving a user by ID using route parameters and dependency injection. It utilizes attributes from 'TerraScale.MinimalEndpoints' for routing and grouping. The endpoint takes an integer 'id' from the route and an 'IUserService' from dependency injection, returning a 'User' object or null. It's designed for ASP.NET Core applications using TerraScale.MinimalEndpoints. ```csharp using Microsoft.AspNetCore.Mvc; using TerraScale.MinimalEndpoints.Attributes; using TerraScale.MinimalEndpoints.Example.Models; using TerraScale.MinimalEndpoints.Example.Services; namespace TerraScale.MinimalEndpoints.Example.Endpoints; [MinimalEndpoints("api/users")] [EndpointGroupName("User Management")] public class GetUserEndpoint : BaseMinimalApiEndpoint { /// /// Gets a user by ID /// /// The user ID /// The user service /// The user if found, or null /// User found or null if not found [HttpGet("{id}")] [Produces("application/json")] public async Task GetUser([FromRoute] int id, [FromServices] IUserService userService) { await Task.Delay(1); return userService.Get(id); } } // Request: GET /api/users/42 // Response: {"id": 42, "name": "John Doe"} or null ``` -------------------------------- ### GET /api/weather Source: https://context7.com/mariogk/terrascale.minimalendpoints/llms.txt Retrieves weather information for a specified city. This endpoint demonstrates query parameter binding. ```APIDOC ## GET /api/weather ### Description Gets weather information for a city using a query parameter. Currently returns static sunny weather. ### Method GET ### Endpoint /api/weather ### Parameters #### Query Parameters - **city** (string) - Required - The name of the city to get weather information for. ### Response #### Success Response (200) - **weather** (string) - A string describing the weather for the specified city. #### Error Response (400) Invalid city name provided. ### Response Example ``` "Weather in Boston is Sunny" ``` ``` -------------------------------- ### Implement Thread-Safe Service Layer for Endpoint Consumption Source: https://context7.com/mariogk/terrascale.minimalendpoints/llms.txt Implement a thread-safe service layer for endpoint consumption, ensuring data integrity in concurrent scenarios. This example uses C# with `ConcurrentDictionary` and `Interlocked` for thread-safe operations on user data. ```csharp using System.Collections.Concurrent; using TerraScale.MinimalEndpoints.Example.Models; namespace TerraScale.MinimalEndpoints.Example.Services; public interface IUserService { User Create(string name); User? Get(int id); User? Update(int id, string name); bool Delete(int id); } public class UserService : IUserService { private static readonly ConcurrentDictionary Users = new(); private static int _nextId = 0; public User Create(string name) { var id = Interlocked.Increment(ref _nextId); var user = new User(id, name); Users.TryAdd(id, user); return user; } public User? Get(int id) { return Users.TryGetValue(id, out var user) ? user : null; } public User? Update(int id, string name) { if (Users.TryGetValue(id, out var user)) { var updated = user with { Name = name }; Users.TryUpdate(id, updated, user); return updated; } return null; } public bool Delete(int id) { return Users.TryRemove(id, out _); } } // Register in Program.cs: // builder.Services.AddSingleton(); ``` -------------------------------- ### Implement IMinimalEndpoint Interface for Grouping and Tagging Source: https://context7.com/mariogk/terrascale.minimalendpoints/llms.txt Implement the IMinimalEndpoint interface to group and tag custom endpoints. This involves creating a class that implements the interface and defines GroupName and Tags properties. The example uses C# and the Microsoft.AspNetCore.Mvc namespace. ```csharp using TerraScale.MinimalEndpoints; using TerraScale.MinimalEndpoints.Attributes; using Microsoft.AspNetCore.Mvc; namespace MyApp.Endpoints; [MinimalEndpoints("api/admin")] public class AdminEndpoint : IMinimalEndpoint { public string? GroupName => "Administration"; public string[]? Tags => new[] { "admin", "management" }; [HttpGet("stats")] [Produces("application/json")] public async Task GetStats() { await Task.Delay(1); return new { TotalUsers = 100, ActiveSessions = 25 }; } } // OpenAPI will group this endpoint under "Administration" with tags "admin" and "management" ``` -------------------------------- ### GET /api/secure Source: https://context7.com/mariogk/terrascale.minimalendpoints/llms.txt Retrieves secured data. This endpoint has logging applied via an EndpointFilter and is associated with the 'secure' group. ```APIDOC ## GET /api/secure ### Description Retrieves secured data. This endpoint has logging applied via an EndpointFilter and is associated with the 'secure' group. ### Method GET ### Endpoint /api/secure ### Parameters #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **response** (string) - Secured data. #### Response Example ```json "Secured data" ``` ``` -------------------------------- ### Document Multiple Response Status Codes with ResponseDescription Attribute Source: https://context7.com/mariogk/terrascale.minimalendpoints/llms.txt Use the ResponseDescription attribute to document multiple response status codes for comprehensive OpenAPI documentation. This attribute can be applied to methods to specify descriptions for different HTTP status codes. The example uses C#. ```csharp using TerraScale.MinimalEndpoints.Attributes; using Microsoft.AspNetCore.Mvc; namespace MyApp.Endpoints; [MinimalEndpoints("api/orders")] public class OrderEndpoint : BaseMinimalApiEndpoint { [HttpPost] [ResponseDescription(201, "Order created successfully")] [ResponseDescription(400, "Invalid order data")] [ResponseDescription(409, "Order already exists")] [ResponseDescription(500, "Internal server error")] [Produces("application/json")] [Consumes("application/json")] public async Task CreateOrder([FromBody] OrderRequest request) { if (request.Amount <= 0) return BadRequest(new { error = "Invalid amount" }); if (await OrderExistsAsync(request.OrderId)) return Problem("Order already exists", statusCode: 409); var order = await CreateOrderAsync(request); return Created($"/api/orders/{order.Id}", order); } private async Task OrderExistsAsync(string orderId) => await Task.FromResult(false); private async Task CreateOrderAsync(OrderRequest request) => await Task.FromResult(new Order(request.OrderId, request.Amount)); } public record OrderRequest(string OrderId, decimal Amount); public record Order(string Id, decimal Amount); ``` -------------------------------- ### GET /api/admin/stats Source: https://context7.com/mariogk/terrascale.minimalendpoints/llms.txt Retrieves administrative statistics, such as total users and active sessions. This endpoint is grouped under 'Administration' with 'admin' and 'management' tags. ```APIDOC ## GET /api/admin/stats ### Description Retrieves administrative statistics, such as total users and active sessions. ### Method GET ### Endpoint /api/admin/stats ### Parameters #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **TotalUsers** (integer) - The total number of users. - **ActiveSessions** (integer) - The number of active user sessions. #### Response Example ```json { "TotalUsers": 100, "ActiveSessions": 25 } ``` ``` -------------------------------- ### Apply EndpointFilter Attribute for Cross-Cutting Concerns Source: https://context7.com/mariogk/terrascale.minimalendpoints/llms.txt Apply the EndpointFilter attribute to endpoints for managing cross-cutting concerns like logging, validation, or rate limiting. Filters must implement IEndpointFilter and can be applied at both class and method levels. This example uses C#. ```csharp using TerraScale.MinimalEndpoints.Attributes; using Microsoft.AspNetCore.Mvc; namespace MyApp.Endpoints; [MinimalEndpoints("api/secure")] [EndpointFilter(typeof(RateLimitFilter))] public class SecureEndpoint : BaseMinimalApiEndpoint { [HttpGet] [EndpointFilter(typeof(LoggingFilter))] public async Task GetData() { await Task.Delay(1); return "Secured data"; } } // Filters must implement IEndpointFilter // Multiple filters can be applied at class or method level ``` -------------------------------- ### Build Project with .NET CLI Source: https://github.com/mariogk/terrascale.minimalendpoints/blob/main/AGENTS.md Builds the .NET project. During the build process, a source generator runs to automatically create registration code for minimal endpoints. ```bash dotnet build ``` -------------------------------- ### POST Endpoint with Request Body, Authorization, and XML Docs Source: https://context7.com/mariogk/terrascale.minimalendpoints/llms.txt This C# code defines a POST endpoint for creating a new user. It accepts a JSON request body, injects an 'IUserService', and requires 'Admin' role authorization. The endpoint includes comprehensive XML documentation for OpenAPI, detailing parameters, responses, and remarks. It's built for ASP.NET Core applications utilizing TerraScale.MinimalEndpoints for structured API development. ```csharp using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using TerraScale.MinimalEndpoints.Attributes; using TerraScale.MinimalEndpoints.Example.Models; using TerraScale.MinimalEndpoints.Example.Services; namespace TerraScale.MinimalEndpoints.Example.Endpoints; [MinimalEndpoints("api/users")] [EndpointGroupName("User Management")] public class CreateUserEndpoint : BaseMinimalApiEndpoint { /// /// Creates a new user /// /// The user creation request /// The user service /// The newly created user /// /// This endpoint requires Admin privileges to create new users. /// The user ID will be automatically generated. /// /// User created successfully /// Invalid user data provided /// Admin privileges required [HttpPost] [Authorize(Roles = "Admin")] [Produces("application/json")] [Consumes("application/json")] public async Task CreateUser([FromBody] CreateUserRequest request, [FromServices] IUserService userService) { await Task.Delay(10); return userService.Create(request.Name); } } public record CreateUserRequest(string Name); public record User(int Id, string Name); // Request: POST /api/users // Headers: Authorization: Bearer // Body: {"name": "Jane Smith"} // Response: {"id": 1, "name": "Jane Smith"} (HTTP 201) ``` -------------------------------- ### Basic Endpoint Registration Source: https://context7.com/mariogk/terrascale.minimalendpoints/llms.txt Demonstrates how to register all minimal endpoints in an ASP.NET Core application using the generated extension methods. This involves adding services and then mapping the endpoints. ```APIDOC ## Basic Endpoint Registration ### Description Register all minimal endpoints in your ASP.NET Core application using the generated extension methods. This involves configuring the service collection and the application pipeline. ### Method Configuration (Program.cs) ### Endpoint N/A (Configuration step) ### Parameters N/A ### Request Example ```csharp using TerraScale.MinimalEndpoints; using TerraScale.MinimalEndpoints.Example.Services; var builder = WebApplication.CreateBuilder(args); // Register your application services builder.Services.AddSingleton(); builder.Services.AddSingleton(); // Automatically discovers and registers all endpoint classes builder.Services.AddMinimalEndpoints(); var app = builder.Build(); app.UseHttpsRedirection(); // Maps all discovered endpoints to their routes app.MapMinimalEndpoints(); app.Run(); ``` ### Response N/A (Configuration step) ``` -------------------------------- ### POST /api/orders Source: https://context7.com/mariogk/terrascale.minimalendpoints/llms.txt Creates a new order. Supports multiple response descriptions for different status codes (201, 400, 409, 500) and consumes JSON. ```APIDOC ## POST /api/orders ### Description Creates a new order. Supports multiple response descriptions for different status codes (201, 400, 409, 500) and consumes JSON. ### Method POST ### Endpoint /api/orders ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **OrderId** (string) - Required - The ID of the order. - **Amount** (decimal) - Required - The amount of the order. ### Request Example ```json { "OrderId": "order123", "Amount": 100.50 } ``` ### Response #### Success Response (201) - **Id** (string) - The ID of the created order. - **Amount** (decimal) - The amount of the created order. #### Error Response (400) - **error** (string) - Description of the validation error. #### Error Response (409) - **detail** (string) - Message indicating the order already exists. #### Error Response (500) - **status** (integer) - The HTTP status code. - **title** (string) - A title for the error. - **detail** (string) - A detailed explanation of the error. #### Response Example (201) ```json { "Id": "order123", "Amount": 100.50 } ``` ``` -------------------------------- ### POST /api/users Source: https://context7.com/mariogk/terrascale.minimalendpoints/llms.txt Create a new user resource. This endpoint accepts a JSON request body containing the user's name and requires administrator privileges for execution. ```APIDOC ## POST /api/users ### Description Creates a new user with the provided details. This endpoint requires authentication and authorization for administrators, accepts a JSON payload, and returns the created user. ### Method POST ### Endpoint /api/users ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body - **request** (CreateUserRequest) - Required - The data for creating a new user. Expected to be a JSON object with a 'name' (string) field. ### Request Example ```json { "name": "Jane Smith" } ``` ### Request Example (with Authorization Header) `POST /api/users` `Headers: Authorization: Bearer ` ### Response #### Success Response (201) - **User** (object) - The newly created user object, including its generated ID and name. #### Error Response (400) - Invalid user data provided. #### Error Response (403) - Admin privileges required. #### Response Example ```json { "id": 1, "name": "Jane Smith" } ``` ``` -------------------------------- ### Implement PUT Endpoint with IResult Response (C#) Source: https://context7.com/mariogk/terrascale.minimalendpoints/llms.txt Demonstrates how to create a PUT endpoint to update an existing resource. It returns an IResult, returning Ok with the updated user if successful, or NotFound if the user does not exist. Dependencies include Microsoft.AspNetCore.Mvc and TerraScale.MinimalEndpoints. ```csharp using Microsoft.AspNetCore.Mvc; using TerraScale.MinimalEndpoints.Attributes; using TerraScale.MinimalEndpoints.Example.Models; using TerraScale.MinimalEndpoints.Example.Services; namespace TerraScale.MinimalEndpoints.Example.Endpoints; [MinimalEndpoints("api/users")] [EndpointGroupName("User Management")] public class UpdateUserEndpoint : BaseMinimalApiEndpoint { [HttpPut("{id}")] [Produces("application/json")] [Consumes("application/json")] public async Task UpdateUser([FromRoute] int id, [FromBody] UpdateUserRequest request, [FromServices] IUserService userService) { await Task.Delay(1); var user = userService.Update(id, request.Name); return user != null ? Results.Ok(user) : Results.NotFound(); } } public record UpdateUserRequest(string Name); // Request: PUT /api/users/42 // Body: {"name": "Updated Name"} // Response: {"id": 42, "name": "Updated Name"} (HTTP 200) or HTTP 404 ``` -------------------------------- ### Define ASP.NET Core Minimal API Endpoint with C# Source: https://github.com/mariogk/terrascale.minimalendpoints/blob/main/README.md This snippet demonstrates how to define a user creation endpoint using TerraScale.MinimalEndpoints. It implements `BaseMinimalApiEndpoint`, uses attributes like `[MinimalEndpoints]` for routing and `[HttpPost]` for the HTTP method, and supports dependency injection via `[FromServices]` and request body binding with `[FromBody]`. ```csharp using Microsoft.AspNetCore.Mvc; using MinimalEndpoints; using MinimalEndpoints.Attributes; [MinimalEndpoints("api/v1/users")] [EndpointGroupName("User Management")] public class CreateUserEndpoint : BaseMinimalApiEndpoint { [HttpPost] [Produces("application/json", StatusCode = 201)] [Consumes("application/json")] public async Task CreateUser( [FromServices] IUserService userService, [FromBody] CreateUserRequest request) { var user = await userService.CreateAsync(request); return user; } } ``` -------------------------------- ### Registering Minimal Endpoints in ASP.NET Core Source: https://context7.com/mariogk/terrascale.minimalendpoints/llms.txt This C# code demonstrates how to register and map Minimal Endpoints in an ASP.NET Core application. It requires the 'TerraScale.MinimalEndpoints' NuGet package. The code injects application services, calls 'AddMinimalEndpoints()' to discover and register endpoints, and 'MapMinimalEndpoints()' to map them to routes. ```csharp using TerraScale.MinimalEndpoints; using TerraScale.MinimalEndpoints.Example.Services; var builder = WebApplication.CreateBuilder(args); // Register your application services builder.Services.AddSingleton(); builder.Services.AddSingleton(); // Automatically discovers and registers all endpoint classes builder.Services.AddMinimalEndpoints(); var app = builder.Build(); app.UseHttpsRedirection(); // Maps all discovered endpoints to their routes app.MapMinimalEndpoints(); app.Run(); ``` -------------------------------- ### Implement DELETE Endpoint with IResult Response (C#) Source: https://context7.com/mariogk/terrascale.minimalendpoints/llms.txt Shows how to create a DELETE endpoint to remove a resource. It returns an IResult indicating the success or failure of the deletion operation. Dependencies include Microsoft.AspNetCore.Mvc and TerraScale.MinimalEndpoints. ```csharp using Microsoft.AspNetCore.Mvc; using TerraScale.MinimalEndpoints.Attributes; using TerraScale.MinimalEndpoints.Example.Services; namespace TerraScale.MinimalEndpoints.Example.Endpoints; [MinimalEndpoints("api/users")] [EndpointGroupName("User Management")] public class DeleteUserEndpoint : BaseMinimalApiEndpoint { [HttpDelete("{id}")] [Produces("application/json")] public async Task DeleteUser([FromRoute] int id, [FromServices] IUserService userService) { await Task.Delay(1); var result = userService.Delete(id); return Results.Ok(result); } } // Request: DELETE /api/users/42 // Response: true (HTTP 200) if deleted, false if not found ``` -------------------------------- ### Define ASP.NET Core Minimal API Endpoint with Attributes (C#) Source: https://github.com/mariogk/terrascale.minimalendpoints/blob/main/AGENTS.md This snippet demonstrates how to define an ASP.NET Core minimal API endpoint using TerraScale.MinimalEndpoints. It utilizes attributes to specify the base route, OpenAPI group name, HTTP method, authorization requirements, and content types. The endpoint takes a request body and injects a service, returning a JSON response. ```csharp [MinimalEndpoints("api/users")] [EndpointGroupName("User Management")] public class CreateUserEndpoint : BaseMinimalApiEndpoint { [HttpPost] [Authorize(Roles = "Admin")] [Produces("application/json", StatusCode = 201)] [Consumes("application/json")] public async Task CreateUser([FromBody] CreateUserRequest request, [FromServices] IUserService userService) { return userService.Create(request.Name); } } ``` -------------------------------- ### Register Minimal Endpoints in ASP.NET Core Program.cs (C#) Source: https://github.com/mariogk/terrascale.minimalendpoints/blob/main/README.md This code registers the necessary services for Minimal Endpoints and maps the discovered endpoints in an ASP.NET Core application. It first adds custom application services like `IUserService` and then uses `builder.Services.AddMinimalEndpoints()` for automatic registration, followed by `app.MapMinimalEndpoints()` to configure routing. ```csharp var builder = WebApplication.CreateBuilder(args); // Add application services builder.Services.AddScoped(); // Register Minimal Endpoints services (automatically registers all endpoint classes) builder.Services.AddMinimalEndpoints(); var app = builder.Build(); // Map Minimal Endpoints routes app.MapMinimalEndpoints(); app.Run(); ``` -------------------------------- ### PUT /api/users/{id} Source: https://context7.com/mariogk/terrascale.minimalendpoints/llms.txt Updates an existing user resource. Returns HTTP 200 with the updated user if successful, or HTTP 404 if the user is not found. ```APIDOC ## PUT /api/users/{id} ### Description Updates an existing user resource and returns appropriate HTTP status codes based on operation outcome. ### Method PUT ### Endpoint /api/users/{id} ### Parameters #### Path Parameters - **id** (int) - Required - The ID of the user to update. #### Request Body - **name** (string) - Required - The updated name for the user. ### Request Example ```json { "name": "Updated Name" } ``` ### Response #### Success Response (200) - **id** (int) - The ID of the updated user. - **name** (string) - The updated name of the user. #### Error Response (404) User not found. #### Response Example (Success) ```json { "id": 42, "name": "Updated Name" } ``` ``` -------------------------------- ### Minimal Endpoint Interface Definition (C#) Source: https://github.com/mariogk/terrascale.minimalendpoints/blob/main/README.md Defines the `IMinimalEndpoint` interface, which all custom endpoint classes must implement when using TerraScale.MinimalEndpoints. It specifies properties for `GroupName` and `Tags`, primarily used for organizing and documenting endpoints in OpenAPI specifications. ```csharp public interface IMinimalEndpoint { string? GroupName { get; } string[]? Tags { get; } } ``` -------------------------------- ### DELETE /api/users/{id} Source: https://context7.com/mariogk/terrascale.minimalendpoints/llms.txt Deletes a user resource by ID. Returns HTTP 200 with a boolean indicating success or failure. ```APIDOC ## DELETE /api/users/{id} ### Description Deletes a user resource by ID and returns the operation result. ### Method DELETE ### Endpoint /api/users/{id} ### Parameters #### Path Parameters - **id** (int) - Required - The ID of the user to delete. ### Response #### Success Response (200) - **result** (boolean) - `true` if the user was deleted successfully, `false` if the user was not found. #### Response Example ```json true ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.