Become a member!

DMVCFramework - The Most Popular Delphi REST API Framework for Web Services

Quick Answer: DMVCFramework is the #1 Delphi framework for building REST APIs and web services. It’s free (Apache 2.0), production-ready since 2010, supports JWT, WebSocket, ORM, and works on Windows/Linux. Install from GitHub, create a controller with [MVCPath] attributes, and return objects that auto-serialize to JSON.

What is DMVCFramework?

DMVCFramework (DelphiMVCFramework) is the most popular open-source framework for building web APIs and web applications in Delphi. It enables you to create RESTful services (RMM Level 3), JSON-RPC services, server-side web pages, mobile backends, and microservices with ease.

Used in production since 2010, DMVCFramework powers some of the highest-traffic Delphi web APIs in the world. It’s the #1 Delphi project on GitHub by star rating, with a vibrant community of 5,000+ active developers.

DMVCFramework Logo

GitHub stars GitHub last commit License

⬇️ Download Latest Release ⭐ GitHub (1.3k+ stars)

Get Started: The Official Guide

DMVCFramework - The Official Guide

The fastest way to master DMVCFramework is through the official guide. This comprehensive book takes you from fundamentals to professional-level development with real-world examples and best practices.

Available Editions

Language Format Link
🇬🇧 English eBook Buy on Leanpub
🇬🇧 English Hardcover Buy on Lulu
🇧🇷 Portuguese eBook Buy on Leanpub
🇪🇸 Spanish eBook Buy on Leanpub

📖 Read a Free Sample Chapter - Get up and running in 5 minutes!


Why Choose DMVCFramework?

Benefit Description
Proven in Production Used since 2010 in small, medium, and enterprise projects worldwide
Complete Feature Set REST, JSON-RPC, JWT, WebSocket, SSE, ORM - everything you need
Blazing Fast Optimized for high performance under heavy workloads
Easy to Learn Intuitive API with 50+ samples to get you productive quickly
Active Community 5,000+ developers in the Facebook group ready to help
Actively Maintained Regular updates, semantic versioning, future-proof

What’s New in DMVCFramework

DMVCFramework is continuously evolving. Here are some of the latest features:

Functional Actions

Return data directly from controller methods - the framework handles serialization automatically. No more Render() calls needed for simple responses:

function TMyController.GetCustomers: TObjectList<TCustomer>;
begin
  Result := FRepository.GetAll;  // Automatically serialized to JSON
end;

WebSocket Support

Full-duplex real-time communication with channel-based messaging, groups, and JavaScript client support. Build chat applications, live dashboards, and collaborative tools.

Server-Sent Events (SSE)

Push notifications from server to client over HTTP. Perfect for live updates, progress indicators, and event streaming.

Repository Pattern with Dependency Injection

Clean architecture with IMVCRepository<T> and [MVCInject] for automatic dependency injection:

[MVCInject]
constructor Create(Repository: IMVCRepository<TCustomer>); reintroduce;

HTMX Integration

Build modern, dynamic web applications with minimal JavaScript using HTMX and TemplatePro or WebStencils.

Sqids Support

Generate short, unique, URL-friendly IDs from numbers. Perfect for public-facing identifiers.

Enhanced Security

Rate limiting middleware (in-memory and Redis-backed), JWT blacklisting, TLS 1.3 support, and secure HTTP-only cookie authentication.


Key Features

Web API Development

  • RESTful APIs - Full RMM Level 3 compliance with proper HTTP verbs and status codes
  • JSON-RPC 2.0 - Automatic object remoting for RPC-style APIs
  • OpenAPI Support - Automatic API documentation generation
  • Automatic Routing - Attribute-based URL mapping with parameter binding

Authentication & Security

  • JWT Authentication - Industry-standard JSON Web Tokens
  • HTTP Basic Authentication - Simple username/password auth
  • Custom Authentication - Flexible framework for any auth scheme
  • CORS Support - Cross-origin resource sharing configuration

Real-Time Communication

  • WebSocket Support - Full-duplex communication channels
  • Server-Sent Events (SSE) - Push notifications to clients
  • Messaging Extensions - Built-in pub/sub patterns

Data & Persistence

  • MVCActiveRecord - Powerful ORM for database operations
  • JSON Serialization - Automatic object-to-JSON mapping
  • Custom Serializers - Full control over data transformation

Deployment Flexibility

  • Windows Console Application
  • Windows Service
  • Linux Console/Daemon
  • Apache Module (mod_proxy)
  • IIS (ISAPI DLL)
  • Load-balanced environments

Developer Experience

  • IDE Wizard - Project templates for quick start
  • 50+ Samples - Learn every feature with working examples
  • Middleware System - Easy request/response hooks
  • Controller Inheritance - DRY principle for common logic
  • Integrated REST Client - Test and consume APIs easily

Quick Start: Hello World

Get started with DMVCFramework in minutes. Here’s a simple “Hello World” controller:

uses
  MVCFramework, MVCFramework.Commons;

type
  [MVCPath('/api')]  // Base path for all actions in this controller
  TMyController = class(TMVCController)
  public
    [MVCPath('/hello')]           // Route: GET /api/hello
    [MVCHTTPMethods([httpGET])]   // Allowed HTTP method
    function GetHello: String;

    [MVCPath('/hello/($Name)')]   // Route: GET /api/hello/{Name}
    [MVCHTTPMethods([httpGET])]   // ($Name) captures the URL segment
    function GetHelloName(const Name: String): String;
  end;

implementation

function TMyController.GetHello: String;
begin
  Result := 'Hello, World!';  // Automatically serialized to JSON
end;

function TMyController.GetHelloName(const Name: String): String;
begin
  Result := 'Hello, ' + Name + '!';  // Name is automatically extracted from URL
end;

That’s it! Call GET /api/hello and you get "Hello, World!". Call GET /api/hello/John and you get "Hello, John!".

DMVCFramework automatically serializes your return values to JSON - strings, objects, arrays, records, datasets - everything just works.


Advanced Example: REST API with Database

For real-world applications, DMVCFramework supports MVCActiveRecord ORM and the Repository pattern with dependency injection:

uses
  MVCFramework, MVCFramework.Commons, MVCFramework.ActiveRecord,
  MVCFramework.Repository, System.Generics.Collections;

type
  // Entity class mapped to database table
  [MVCTable('customers')]
  TCustomer = class(TMVCActiveRecord)
  private
    [MVCTableField('id', [foPrimaryKey, foAutoGenerated])]  // Auto-increment PK
    FID: NullableInt32;
    [MVCTableField('name')]    // Maps to 'name' column
    FName: string;
    [MVCTableField('email')]   // Maps to 'email' column
    FEmail: string;
  public
    property ID: NullableInt32 read FID write FID;
    property Name: string read FName write FName;
    property Email: string read FEmail write FEmail;
  end;

  [MVCPath('/api/customers')]
  TCustomerController = class(TMVCController)
  protected
    fRepository: IMVCRepository<TCustomer>;  // Repository interface
  public
    [MVCInject]  // Dependency injection - repository is automatically provided
    constructor Create(Repository: IMVCRepository<TCustomer>); reintroduce;

    [MVCPath]                     // Route: GET /api/customers
    [MVCHTTPMethods([httpGET])]
    function GetAllCustomers: IMVCResponse;

    [MVCPath('/($ID)')]           // Route: GET /api/customers/{ID}
    [MVCHTTPMethods([httpGET])]
    function GetCustomerByID(const ID: Integer): IMVCResponse;

    [MVCPath]                     // Route: POST /api/customers
    [MVCHTTPMethods([httpPOST])]  // [MVCFromBody] deserializes JSON body to TCustomer
    function CreateCustomer([MVCFromBody] const Customer: TCustomer): IMVCResponse;

    [MVCPath('/($ID)')]           // Route: DELETE /api/customers/{ID}
    [MVCHTTPMethods([httpDELETE])]
    function DeleteCustomerByID(const ID: Integer): IMVCResponse;
  end;

implementation

constructor TCustomerController.Create(Repository: IMVCRepository<TCustomer>);
begin
  inherited Create;
  fRepository := Repository;  // Store injected repository
end;

function TCustomerController.GetAllCustomers: IMVCResponse;
begin
  Result := OKResponse(fRepository.GetAll);  // Returns HTTP 200 with JSON array
end;

function TCustomerController.GetCustomerByID(const ID: Integer): IMVCResponse;
begin
  Result := OKResponse(fRepository.GetByPK(ID));  // Returns HTTP 200 with JSON object
end;

function TCustomerController.CreateCustomer(const Customer: TCustomer): IMVCResponse;
begin
  fRepository.Store(Customer);  // Insert or update based on PK
  Result := CreatedResponse('/api/customers/' + Customer.ID.Value.ToString);  // HTTP 201
end;

function TCustomerController.DeleteCustomerByID(const ID: Integer): IMVCResponse;
var
  lCustomer: TCustomer;
begin
  lCustomer := fRepository.GetByPK(ID);  // Load entity by primary key
  fRepository.Delete(lCustomer);          // Delete from database
  Result := OKResponse;                   // Returns HTTP 200
end;

Key benefits:

  • Functional actions: Return IMVCResponse using helpers like OKResponse(), CreatedResponse()
  • Dependency injection: [MVCInject] on constructor for automatic repository injection
  • MVCActiveRecord: ORM with table mapping via attributes
  • Repository pattern: IMVCRepository<T> for clean, testable data access
  • Auto-serialization: Objects, records, lists, datasets are automatically serialized

Learn by Example: 100+ Sample Projects

The best way to learn DMVCFramework is by exploring working code. The project includes over 100 sample projects covering every feature and use case. Each sample is self-contained and ready to compile.

Find the sample that matches what you need to build, open it in Delphi, and start experimenting!

📦 All samples: github.com/danieleteti/delphimvcframework/tree/master/samples


“I want to create my first DMVCFramework project”

Sample Description
basicdemo_server Minimal server setup - start here
functional_actions_showcase Modern functional actions pattern
console_sample Simple console application

“I want to build a REST API”

Sample Description
simple_api_using_mvcactiverecord REST API with ORM
simple_api_using_repository_with_injection Repository pattern + dependency injection
simple_api_using_datasets Return TDataSet as JSON
routing URL parameters, path segments, query strings
validators Built-in and custom input validators
file_upload Handle multipart/form-data uploads

“I want to add authentication and security”

Sample Description
jsonwebtoken JSON Web Token basics
jsonwebtoken_roleauth Role-based authorization with JWT
middleware_jwtwithcookiehttponly Secure HTTP-only cookie for JWT
middleware_basicauthentication HTTP Basic authentication
custom_auth Implement your own auth handler
middleware_cors Cross-Origin Resource Sharing
middleware_ratelimit_memory Throttle requests (in-memory)
middleware_ratelimit_redis Throttle requests (Redis-backed)

“I want real-time communication”

Sample Description
websocket_primer WebSocket introduction
websocket_chat Multi-user chat application
websocket_groups Channel-based messaging
websocket_javascript_client_sample Browser client example
serversentevents Server-Sent Events (push notifications)

“I want to render HTML pages”

Sample Description
serversideviews_templatepro HTML with TemplatePro engine
serversideviews_mustache HTML with Mustache engine
htmx Dynamic HTML with HTMX
htmx_website_with_templatepro Full website with HTMX + TemplatePro
htmx_website_with_webstencils RAD Studio WebStencils integration

“I want to work with databases”

Sample Description
activerecord_showcase Complete ORM demo
activerecord_restful_crud RESTful API with ActiveRecord
master_details Parent-child relationships
repository_showcase IMVCRepository usage
ado Microsoft ADO example

“I want to use JSON-RPC”

Sample Description
jsonrpc JSON-RPC 2.0 server implementation

“I want to customize request/response handling”

Sample Description
middleware Create your own middleware
middleware_compression GZIP/Deflate responses
middleware_etag HTTP caching with ETags
middleware_staticfiles Serve static content
middleware_analytics Request logging/tracking
middleware_activerecord Per-request DB connection
action_filters Before/after action hooks
custom_exception_handling Custom error responses
renders Custom JSON serializers

“I want to deploy to production”

Sample Description
windows_service Run as Windows service
apache_module Deploy behind Apache
isapi Deploy on IIS
ssl_server HTTPS configuration
tls13 Modern TLS 1.3 setup

“I want to document my API”

Sample Description
swagger_primer OpenAPI documentation basics
swagger_ui Interactive API explorer
swagger_doc_extended Advanced documentation features

“I want advanced features”

Sample Description
mvcasync Asynchronous actions
outputcachewithredis Redis-backed response cache
prometheus Prometheus monitoring integration
services_injection Dependency injection
dotenv_showcase Environment configuration with .env files
sqids_showcase Short unique IDs (Sqids)


DMVCFramework integrates seamlessly with other open source projects by the same author:

Project Description Use with DMVCFramework
LoggerPro Async logging framework with 20+ appenders Add structured logging to your APIs with file, database, Redis, or ElasticSearch appenders
TemplatePro Powerful template engine with Jinja-like syntax Server-side HTML rendering with serversideviews_templatepro sample
DelphiRedisClient Complete Redis client Caching, session storage, rate limiting, and real-time features
DelphiGuard RAII memory management Automatic resource cleanup in controllers and middleware
Delphi Fake Data Utils Test data generator Generate realistic data for API testing and demos
Expression Evaluator Runtime formula parser Dynamic business rules and calculated fields in your APIs

Delphi Version Compatibility

Delphi Version Windows Linux
Delphi 13 Florence
Delphi 12 Athens
Delphi 11 Alexandria
Delphi 10.4 Sydney
Delphi 10.3 Rio
Delphi 10.2 Tokyo
Delphi 10.1 Berlin -
Delphi 10 Seattle -

Support the Project

🎁 Become a Patron Supporter

DMVCFramework is free and open-source, but maintaining and improving it requires significant effort. By becoming a Patron, you:

  • Access Premium Content - Exclusive tutorials, advanced examples, and early previews
  • Direct Developer Access - Priority support and direct communication with the development team
  • Shape the Future - Influence the roadmap and feature priorities
  • Support Open Source - Help keep DMVCFramework free for everyone

Join on Patreon →


Professional Services

Need enterprise-grade support? bit Time Professionals, the company behind DMVCFramework, offers:

  • Training Courses - On-site or remote training for your team
  • Consulting - Architecture review, performance optimization, best practices
  • Custom Development - Feature development, integration, migration

📧 Contact: dmvcframework@bittime.it | 🌐 bittimeprofessionals.it


Community & Resources

Resource Link
📦 GitHub Repository github.com/danieleteti/delphimvcframework
📕 Official Guide (Book) leanpub.com/delphimvcframework
👥 Facebook Group (5,000+ members) facebook.com/groups/delphimvcframework
🎁 Patreon (Premium Content) patreon.com/delphimvcframework
📖 Free Sample Chapter Read on Leanpub

FAQ: Frequently Asked Questions

What is DMVCFramework?

DMVCFramework (DelphiMVCFramework) is an open-source framework for building web APIs, RESTful services, and web applications in Delphi. It’s the most popular Delphi web framework, used in production since 2010, and is the #1 Delphi project on GitHub by star count.

What is the best framework for REST API in Delphi?

DMVCFramework is the most popular and feature-complete framework for building REST APIs in Delphi. It supports RESTful APIs (RMM Level 3), JSON-RPC, WebSocket, Server-Sent Events, JWT authentication, and includes a powerful ORM called MVCActiveRecord.

How do I create a REST API in Delphi?

Use DMVCFramework: create a controller class inheriting from TMVCController, add [MVCPath] and [MVCHTTPMethods] attributes to define routes, and return data directly from your methods (functional actions). The framework automatically serializes objects, arrays, and records to JSON. See the 100+ included samples for examples.

How do I return JSON from a Delphi REST API?

With DMVCFramework, simply return an object, record, or TObjectList<T> from your controller method. The framework automatically serializes it to JSON. For more control, use OKResponse(data) or CreatedResponse(location) helpers.

Does DMVCFramework support JWT authentication?

Yes, DMVCFramework has built-in JWT (JSON Web Token) support for stateless authentication. It supports token generation, validation, role-based authorization, and secure HTTP-only cookies. See the jsonwebtoken and jsonwebtoken_roleauth samples.

Can I use DMVCFramework on Linux?

Yes, DMVCFramework fully supports Linux deployment starting from Delphi 10.2 Tokyo. You can deploy as a console application or daemon, with full support for all features including WebSocket and SSL/TLS.

Is DMVCFramework free?

Yes, DMVCFramework is free and open-source under the Apache 2.0 license. You can use it in commercial projects without restrictions or attribution requirements.

How do I get support for DMVCFramework?

Multiple support options are available: join the Facebook group (5,000+ members), explore the 100+ samples included in the project, read the official guide book, or become a Patron for priority support and exclusive content.

Does DMVCFramework support WebSocket?

Yes, DMVCFramework includes full WebSocket support for real-time bidirectional communication. Features include channel-based messaging, groups, and JavaScript client examples. It also supports Server-Sent Events (SSE) for server-to-client push notifications.

What is MVCActiveRecord?

MVCActiveRecord is DMVCFramework’s built-in ORM (Object-Relational Mapper) that simplifies database operations. It uses attributes for table/column mapping, supports CRUD operations, relationships, and RQL (Resource Query Language) for flexible querying.

How do I deploy DMVCFramework to production?

DMVCFramework supports multiple deployment options: Windows console application, Windows Service, Linux daemon, Apache module (mod_proxy), IIS (ISAPI DLL), and load-balanced environments. See the deployment samples for each scenario.

Does DMVCFramework support OpenAPI/Swagger?

Yes, DMVCFramework can automatically generate OpenAPI (Swagger) documentation for your APIs. Use the swagger_primer and swagger_ui samples to add interactive API documentation to your project.

How do I handle file uploads in DMVCFramework?

Use the Context.Request object to access uploaded files. The file_upload sample demonstrates handling multipart/form-data requests with single or multiple file uploads.

Can I use DMVCFramework with FireDAC?

Yes, DMVCFramework works with any database access layer including FireDAC, ADO, and others. MVCActiveRecord uses FireDAC by default, but you can use any connection you prefer.

How do I implement CORS in DMVCFramework?

Use the built-in CORS middleware. Add TMVCCORSMiddleware to your server configuration to enable cross-origin requests. See the middleware_cors sample for configuration options.

What Delphi versions does DMVCFramework support?

DMVCFramework supports Delphi 10 Seattle through Delphi 13 Florence, including full Linux support from Delphi 10.2 Tokyo onwards.

How do I handle errors and exceptions in DMVCFramework?

DMVCFramework automatically converts exceptions to appropriate HTTP error responses with JSON bodies. For custom error handling, use raise EMVCException.Create() with specific HTTP status codes, or implement custom exception handlers.

Does DMVCFramework support dependency injection?

Yes, DMVCFramework has built-in dependency injection. Use the [MVCInject] attribute on constructors or method parameters to automatically inject services and repositories. See the services_injection sample.


DMVCFramework - The #1 Delphi framework for Web API. Free. Open-source. Production-ready since 2010.

Comments

comments powered by Disqus