Marcel Medina shares practical API design techniques for .NET developers using the REPR pattern and FastEndpoints, streamlining endpoint development and improving code quality.

Simplifying ASP.NET API Design with the REPR Pattern and FastEndpoints

Presented by Marcel Medina

Overview

Building APIs in ASP.NET often starts with controllers. While controllers are flexible, they can quickly become overly complex as the application grows, mixing routing, validation, and business logic. This session introduces the REPR pattern—Request, Endpoint, Response—as an alternative, emphasizing clarity and separation of concerns.

Key Concepts

  • REPR Pattern:
    • Request: Strongly-typed input models for endpoints, facilitating validation and consistent structure.
    • Endpoint: Encapsulates routing and the core logic for a distinct API operation.
    • Response: Clear and explicit output models, improving maintainability and testability.
  • FastEndpoints Framework:
    • Designed for .NET developers to implement REPR efficiently.
    • Streamlines the creation of isolated, focused endpoints.
    • Encourages explicit request/response patterns minimizing boilerplate.

Benefits of REPR and FastEndpoints

  • Separation of Concerns: Each part of API logic is in its place—no more massive controllers.
  • Readability: Endpoints are self-contained, making it easy to reason about what each does.
  • Better Testing: Isolated endpoints and explicit requests/responses are easier to test.
  • Scalability: Adding new endpoints does not impact existing ones, and code grows in a structured way.

Implementation Highlights

  • Defining Requests
    • Use simple C# classes for input validation and type safety.
  • Creating Endpoints
    • Implement endpoint logic directly, without the baggage of controller conventions.
    • Fine-grained routing and per-endpoint middleware possible.
  • Returning Responses
    • Standardize on clear output models, making APIs predictable and easier to document/use.

Demo Takeaways

  • How to create and organize APIs without controllers.
  • Patterns for validating input, handling failures, and crafting successful responses.
  • Comparison of traditional controllers versus FastEndpoints + REPR.

When to Use

  • Projects suffering from bloated controllers or unclear responsibilities.
  • Teams wanting to improve testing and long-term code health.
  • New APIs where a clean architecture is a top priority.

Further Exploration


This content was presented by Marcel Medina on .NET Live.