#1 2025-12-23 17:11:15

Javierus
Member
Registered: 2019-09-18
Posts: 77

More mORMot2 examples: adapted from DMVCframework

I've adapted more than 40 examples from the DMVCframework to mORMot2

The intention is:
1. Have more examples for mORMot2
2. Help DMVCframework users transition to mORMot2

I've posted them in my own public GitHub, but I would be very glad if Arnaud is willing to add them to mORMot2 samples

https://github.com/JavierusTk/dmvc

Offline

#2 2025-12-23 18:57:51

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,350
Website

Re: More mORMot2 examples: adapted from DMVCframework

Sounds amazing!

Perhaps we could add them as git sub-modules?
By default, no sub-module would be loaded, but if --recurse-submodules is defined, then all third party samples would be included?

But sub-modules could be confusing, and samples are mostly for beginners, so they may expect to have as many sample as possible to find their way into the code...
My other concern is that if it is part of the main repository, they would need to be maintained somewhat. And it is already not so easy to maintain our third-party samples...

Or we could just add them to the third party folder of the mormot 2 repository? Perhaps if there are a lot of sample there, everyone would understand that they are not at the same level of maintainability?

Worth a common discussion...

Offline

#3 2025-12-24 03:25:53

zen010101
Member
Registered: 2024-06-15
Posts: 163

Re: More mORMot2 examples: adapted from DMVCframework

Wow, there are so many demo programs! It feels like their number has even exceeded the examples that come with mORMot itself! I don't think anyone would dislike more examples, heh heh.

Personally, I still prefer the ThirdParty solution. Just like it is now, it can greatly reduce everyone's cost of obtaining examples.

Offline

#4 2025-12-24 10:18:26

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,350
Website

Re: More mORMot2 examples: adapted from DMVCframework

OK.
I have included the samples as https://github.com/synopse/mORMot2/commit/13fe46e06
into https://github.com/synopse/mORMot2/tree … os/dmvc-ai
(I trimmed some *.rsm files from the original repository)

Now users won't complain about the lack of samples!
Thanks a lot for sharing.
All this AI-generated stuff is very interesting.

Offline

#5 Yesterday 15:57:44

rcla
Member
Registered: 2025-12-13
Posts: 11

Re: More mORMot2 examples: adapted from DMVCframework

@Javierus , Thank you very much for all that number of examples, in addition to all the SAD documentation that you have provided.

I'm using FPC 3.2.3 (fixes) with Windows 11 and wanted to learn about HTTP Basic Authentication.
So I took the "08-basicauth" example, but I ran into the following issues:

  1. It was showing a related error that "RegisterInterfaces" was missing...
    I fixed it by adding the following code to the "api.interfaces.pas" file:

    initialization
      TInterfaceFactory.RegisterInterfaces([TypeInfo(IBasicAuthApi)]);
  2. Inside the Log file, an error related to "useHttpApiRegisteringURI" is displayed.
    "TRestHttpServer(06222840) Create: HttpSetServiceConfiguration() failed: ERROR_ACCESS_DENIED (5) for root - useHttpApiRegisteringURI may need admin rights"
    "EXC   ERestHttpServer {Message:"TRestHttpServer: http.sys URI registration error ERROR_ACCESS_DENIED for http://+:8080/root (you need to register the URI - try to use useHttpApiRegisteringURI)"}"
    I solved it by changing from "HTTP_DEFAULT_MODE" to "useHttpAsync"

      // Create HTTP server
      fHttpServer := TRestHttpServer.Create(aPort, [fRestServer],
        '+', useHttpAsync, {threaded=}32); 
  3. It showed several memory leaks when exiting the program.
    I solved it by adding a variable "fModel: TOrmModel;" and you don't need to free "fBasicAuthApi"

      // Create in-memory REST server (no database needed)
      fModel := TOrmModel.Create([]);
      fRestServer := TRestServerFullMemory.Create(
        fModel, 'root', {authentication=}true); 
    
    destructor TBasicAuthServer.Destroy;
    begin
      Stop;
      fHttpServer.Free;
      //fBasicAuthApi.Free;
      fModel.Free;
      fRestServer.Free;
      inherited Destroy;
    end;
  4. The program did not work correctly, with or without authentication it did not show the expected results. 
    After spending hours understanding how it worked, I found that the problem is with "methodName"

    For some reason "Ctxt.UriMethodPath" always returns empty.
    And within the code you have to:

      methodName := Ctxt.UriMethodPath;
      if methodName = '' then
      begin
        // Fallback to full URI
        methodName := Ctxt.Call^.Url;
      end;

    The problem is that it returns the entire Url.
    For example, we obtain that:
    methodName ="root/BasicAuthApi.PublicSection" , but it was expected that methodName ="PublicSection"
    methodName ="root/BasicAuthApi.OnlyRole2" , but it was expected that methodName ="OnlyRole2"
    methodName ="root/BasicAuthApi.OnlyRole1Json?par1=hello" , but it was expected that methodName ="OnlyRole1Json"

    I solved it by doing the following code (maybe not the best solution, but it works)

      methodName := Ctxt.UriMethodPath;
      if methodName = '' then
      begin
        tmpUrl := Ctxt.Call^.Url;
        mPosIni := PosI('.',tmpUrl) + 1;
        mPosEnd := PosI('?',tmpUrl);
        if mPosEnd >0 then
          mLen :=  mPosEnd - mPosIni
        else
          mLen := length(tmpUrl);
        methodName := Copy(tmpUrl,mPosIni,mLen);
      end;

Offline

Board footer

Powered by FluxBB