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

Antonio Alcázar
Member
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.
https://github.com/miteruel/todorosetta

   
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.


Angular-filemanager
https://github.com/joni2back/angular-filemanager

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 :

sample:
(* 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;
a:Variant;
begin
     path:=normalPath(param.params.path);
     newPath:=normalPath(param.params.newPath);
     try
     if RenameFile (path,newpath) then
     begin
       a:=_Obj(['sucess',true,'error','null']);
     end else
     begin
       a:=_Obj(['sucess',false,'error',KKERRORrename]);
     end;
     result:=responseVariant(a);
     except
       result:=ErrorGenerico (KKrename);
     end;
end;



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. 
/principal/index.html
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:
  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;

Example

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;
begin
      s: = todo.GetFilePost (Ctxt.URL, Ctxt.InContent)
      Ctxt.OutContent: = s;
      Ctxt.OutContentType: = MimeType (ctxt. URL);
      if s = '' then
      begin
        result: = 404;
      end else
      begin
        result: = 200;
      end;
end;



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.


ToDo2 FAQS


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:
https://sites.google.com/a/miteruel.com/dojo/mormot

Offline

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

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

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.

Offline

Board footer

Powered by FluxBB