#1 2015-09-29 17:02:27

Antonio Alcázar
Registered: 2015-09-29
Posts: 1

samples of http server in mORMot

I am a very fan of mORMot.

Because I am impressed with the library, i was working in some experiments to learn more in the basic component use. json,http, zips…
I have published the code for experiment with github.

The examples uses at least 3 mORMot features.

JSON  Reading and rendering.
Zip. (Instead of using another use next in the library)
THttpServer. Basic HTTP server. In the SynCrtSock.pas unit.


I liked the design of this project, and it's great to integrate it into a Web server.
It is easy to implement server-side functions. So I implemented a seed in Delphi. Still not working all commands, but gives an idea of purpose.
It uses mMORmot Json features :

(* Rename / Move (URL: fileManagerConfig.renameUrl, Method: POST)

JSON Request content

{ "params": {
   "mode": "rename",
   "path": "/public_html/index.php",
   "newPath": "/public_html/index2.php"

JSON Response

{ "result": { "success": true, "error": null } }

function rename(param:Variant): SString;
var path,newPath:SString;
     if RenameFile (path,newpath) then
     end else
       result:=ErrorGenerico (KKrename);

The idea is to shape a component that serves to test with Javascript libraries downloaded from GitHub (for example) without unzipping.

A) Simple HTTP server for todoMVC

1) Put the exe  Todo2.exe in the same directory where is todomvc-master.zip
(in example is in e: \ all)

2) execute
\> todo2

3) Open Internet Explorer and access to
http: // localhost: 8082

B) HTTP server for angular-filemanager-master, (with partial file operations)
1) put angular-filemanager-master.zip file in same directory than todo2

2) execute
\ > todo2 angular-filemanager-master

3) Open Internet Explorer and access to
http: // localhost: 8082

Information for programmers.

A web server is a program that serves HTTP requests, in many cases represents a file with static content, type HTML, JS, CSS.
The file name is usually in the URL. 
instructed to return the index.html file inside the main folder.

TTodoServer function is very simple.
It passes the URL of a file, and returns the contents of that file.
The component will search the zip files downloaded the most likely file decompressed.

This is the basic method of the component

  url path (with params if possible)
  post: Posted in POST request content types
  result.The file related or

   GetFilePost function ( const url, post: String): String;


Todo.GetFilePost ('/principal/index.html', '');

return the index.html file in the folder / master

This is an example of use in Mormot:

TTestServer.Process function (ctxt: THttpServerRequest): cardinal;
var s: String;
      s: = todo.GetFilePost (Ctxt.URL, Ctxt.InContent)
      Ctxt.OutContent: = s;
      Ctxt.OutContentType: = MimeType (ctxt. URL);
      if s = '' then
        result: = 404;
      end else
        result: = 200;

If the requested file is in a zip, decompresses on the fly and returns it as if it were a file read directly.

If the required file is not within the zip, or not within the requested path, you can make searches within an order of preferences in other ways or external zip files, searching for files that could match the sought .

We will create an open source code libraries using open source as well, serving as an example to do the same with different libraries initiative and serve all over rossetta .

I am sure that eventually we will use it for different purposes.


Why the name?
ToDo_ToDoMVC, the idea is to make related todoMVC tools and all other libraries ToDo , executable from the command line. todo2 for short name

I’m very sorry for my poor english,
There is a link with Spanish help
https://sites.google.com/a/miteruel.com … odotodomvc

And there is my little contribution for spanish mORMot users:


#2 2015-09-30 12:48:50

From: France
Registered: 2010-06-21
Posts: 13,953

Re: samples of http server in mORMot

Thanks a lot for the nice feedback, and experiment/source sharing!

And for writing some content in Spanish about our little framework.


Board footer

Powered by FluxBB