20
Delphi MVC Framework Mathias Pannier

Delphi MVC Framework - WordPress.com...2016/02/01  · Aboutme • Name: Mathias Pannier • Position: Software developer/ Team leader • More than 15 years of experience with software

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Delphi MVC Framework - WordPress.com...2016/02/01  · Aboutme • Name: Mathias Pannier • Position: Software developer/ Team leader • More than 15 years of experience with software

Delphi MVC FrameworkMathias Pannier

Page 2: Delphi MVC Framework - WordPress.com...2016/02/01  · Aboutme • Name: Mathias Pannier • Position: Software developer/ Team leader • More than 15 years of experience with software

About me

• Name: Mathias Pannier

• Position: Software developer / Team leader

• More than 15 years of experience with software development in Delphi

• Blog: mathiaspannier.wordpress.com

mathiaspannier.wordpress.com

Page 3: Delphi MVC Framework - WordPress.com...2016/02/01  · Aboutme • Name: Mathias Pannier • Position: Software developer/ Team leader • More than 15 years of experience with software

DMVCFramework

• Delphi MVC Framework - is a powerful framework for web solution in Delphi (Quelle: https://code.google.com/p/delphimvcframework/)

• Source files for the development of web services (REST Server/Clients)

• Website: https://github.com/danieleteti/delphimvcframework

• Support site: https://www.facebook.com/groups/delphimvcframework

mathiaspannier.wordpress.com

Page 4: Delphi MVC Framework - WordPress.com...2016/02/01  · Aboutme • Name: Mathias Pannier • Position: Software developer/ Team leader • More than 15 years of experience with software

DMVCFramework

• Lead developer and initiator is Daniele Teti (http://www.danieleteti.it- Author of Delphi Cookbook)

• Delphi Cookbook contains some sections about DMVCFramework

• At the moment 4 developer

• First public release 10/29/2013

• Last update January 2016 (Time of presentation is January 2016)

• Works with XE3 and newer

mathiaspannier.wordpress.com

Page 5: Delphi MVC Framework - WordPress.com...2016/02/01  · Aboutme • Name: Mathias Pannier • Position: Software developer/ Team leader • More than 15 years of experience with software

Features

• Simple to use (really)

• RESTful (RMM Level 3) compliant

• Fancy URL with parameter mappings**

• Specialized renders to generate text, html, json**

• Powerful mapper to map json to objects and datasets to objects**

• Can be packaged as stand alone server, apache module (XE6 or better) and ISAPI dll

mathiaspannier.wordpress.com

Page 6: Delphi MVC Framework - WordPress.com...2016/02/01  · Aboutme • Name: Mathias Pannier • Position: Software developer/ Team leader • More than 15 years of experience with software

Features

• Integrated RESTClient

• Messaging extension using STOMP

• Load balancing and cache using REDIS

• It use Embarcadero WebBroker but is not tied to it

• Designed with services and web client app in mind

• Server side generated pages using Mustache (in the past eLua)

• Etc.

• Source: https://github.com/danieleteti/delphimvcframework und https://github.com/danieleteti/delphimvcframework/blob/master/docs/ITDevCON%202013%20-%20Introduction%20to%20DelphiMVCFramework.pdf

mathiaspannier.wordpress.com

Page 7: Delphi MVC Framework - WordPress.com...2016/02/01  · Aboutme • Name: Mathias Pannier • Position: Software developer/ Team leader • More than 15 years of experience with software

mathiaspannier.wordpress.com

Page 8: Delphi MVC Framework - WordPress.com...2016/02/01  · Aboutme • Name: Mathias Pannier • Position: Software developer/ Team leader • More than 15 years of experience with software

REST

• ... representational state transfer (REST) is the software architectural style ... REST's coordinated set of constraints, applied to the design of components in a distributed hypermedia system, can lead to a higher-performing and more maintainable software architecture.

• Constraints: Client-server, Stateless, (HTTP) Cacheable, Uniform interface (URI, HTTP verbs, JSON, HATEOAS – navigation by URIs), Layered system

• Source: https://en.wikipedia.org/wiki/Representational_state_transfer

mathiaspannier.wordpress.com

Page 9: Delphi MVC Framework - WordPress.com...2016/02/01  · Aboutme • Name: Mathias Pannier • Position: Software developer/ Team leader • More than 15 years of experience with software

Architecture

• One application (EXE or ISAPI DLL)

• Several controller (TMVCController)

• Several actions per controller (Methods)

• Controller, action and parameter are parts auf the url

• www.myserver.com/blog/posts/123

mathiaspannier.wordpress.com

Page 10: Delphi MVC Framework - WordPress.com...2016/02/01  · Aboutme • Name: Mathias Pannier • Position: Software developer/ Team leader • More than 15 years of experience with software

1. Example - Delphi WebBroker Application (ISAPI/EXE)

typeTWebModule1 = class(TWebModule)

procedure WebModuleCreate(Sender: TObject);private

DMVC: TMVCEngine;end;

procedureTWebModule1.WebModuleCreate(Sender: TObjec t);begin

DMVC := TMVCEngine.Create(self);DMVC.AddController(TBlogController);

end;

mathiaspannier.wordpress.com

Page 11: Delphi MVC Framework - WordPress.com...2016/02/01  · Aboutme • Name: Mathias Pannier • Position: Software developer/ Team leader • More than 15 years of experience with software

1. Example – The controllertype

[MVCPath('/blog')]

TBlogController = class(TMVCController)

public

[MVCPath('/posts/($id)')]

procedure GetPostByID(CTX: TWebContext);

end;

implementation

procedure TBlogController.GetPostByID(CTX: TWebContext);

var

aBlogPost: TBlogPost;

begin

aBlogPost := LoadFromDataBaseByID(CTX.Request.Parameters['id'].ToInteger);

Render(aBlogPost);

end;

mathiaspannier.wordpress.com

Page 12: Delphi MVC Framework - WordPress.com...2016/02/01  · Aboutme • Name: Mathias Pannier • Position: Software developer/ Team leader • More than 15 years of experience with software

Parameter

• CTX.Request.Params['id']

• URL Mapped parameters

• Query String parameters

• Form parameters (HTML Form Submit)

• Cookie fields

• Bsp.: • www.myserver.com/blog/posts/123

• www.myserver.com/blog/posts?id=123

mathiaspannier.wordpress.com

Page 13: Delphi MVC Framework - WordPress.com...2016/02/01  · Aboutme • Name: Mathias Pannier • Position: Software developer/ Team leader • More than 15 years of experience with software

Renders

• Methods of the controller to produce the response stream

• Renders can set the HTTP Status Code and the Content Type

• Currently you can render

• Text, DataSets, JSONValues, Delphi Objects, List of Delphi Objects, Exceptions, HTML pages using Mustache, Raw Streams

mathiaspannier.wordpress.com

Page 14: Delphi MVC Framework - WordPress.com...2016/02/01  · Aboutme • Name: Mathias Pannier • Position: Software developer/ Team leader • More than 15 years of experience with software

Renders exampleprocedure TBlogController.GetPostByID(CTX: TWebConte xt);

var

aBlogPost: TBlogPost;

begin

aBlogPost := TBlogPost.Create;

aBlogPost.ID := CTX.Request.Parameters['id'].ToInte ger;

aBlogPost.Title := 'Hello World.';

aBlogPost.Body := 'This is a test message.';

aBlogPost.CreateDate := Now();

aBlogPost.Author := 'Mathias Pannier';

Render(aBlogPost);

end;

procedure TBlogController.GetPostByID(CTX: TWebConte xt);

begin

DataSet1.SelectSQL.Add('select * from BLOG_POSTS wher e ID = :ID');

DataSet1.Params[0].AsInteger := CTX.Request.Paramete rs['id'].ToInteger;

DataSet1.Open;

Render(DataSet1);

end;

mathiaspannier.wordpress.com

Page 15: Delphi MVC Framework - WordPress.com...2016/02/01  · Aboutme • Name: Mathias Pannier • Position: Software developer/ Team leader • More than 15 years of experience with software

Mapper

• „Converter" for Delphi Objects, JSon and DataSets

• Example.:

• ObjectToJSONObject

• JSONObjectToObject

• DataSetToJSONArray

• JSONArrayToDataSet

• ...

• Can be used independent of the DMVCFramework

mathiaspannier.wordpress.com

Page 16: Delphi MVC Framework - WordPress.com...2016/02/01  · Aboutme • Name: Mathias Pannier • Position: Software developer/ Team leader • More than 15 years of experience with software

Mapper example

procedure TForm1.Button1Click(Sender: TObject);

var

aBlogPost: TBlogPost;

begin

aBlogPost := TBlogPost.Create;

aBlogPost.ID := 1;

aBlogPost.Title := 'Hello world.';

aBlogPost.Body := 'This is a test message.';

aBlogPost.CreateDate := Now();

aBlogPost.Author := 'Mathias Pannier';

ShowMessage(Mapper.ObjectToJSONObjectString(aBlogPost));

aBlogPost.Free;

end;

mathiaspannier.wordpress.com

Page 17: Delphi MVC Framework - WordPress.com...2016/02/01  · Aboutme • Name: Mathias Pannier • Position: Software developer/ Team leader • More than 15 years of experience with software

Demo

mathiaspannier.wordpress.com

Page 18: Delphi MVC Framework - WordPress.com...2016/02/01  · Aboutme • Name: Mathias Pannier • Position: Software developer/ Team leader • More than 15 years of experience with software

Alternatives

• Hand made with Indy components

• DataSnap (Embarcadero; shipped with Delphi)

• mORMot Framework

• TMS XData

• kbmMW

• RemObjects

• Etc.

mathiaspannier.wordpress.com

Page 19: Delphi MVC Framework - WordPress.com...2016/02/01  · Aboutme • Name: Mathias Pannier • Position: Software developer/ Team leader • More than 15 years of experience with software

Why DMVCFramework

• Lightweight, small, fast

• Easy to use

• Open source

• Closer to REST/Web development/HTTP

• Mapper/Renders independently usable

• Performance and stability of DataSnap ... (https://robertocschneiders.wordpress.com/2012/11/22/datasnap-analysis-based-on-speed-stability-tests/)

mathiaspannier.wordpress.com

Page 20: Delphi MVC Framework - WordPress.com...2016/02/01  · Aboutme • Name: Mathias Pannier • Position: Software developer/ Team leader • More than 15 years of experience with software

Questions?

mathiaspannier.wordpress.com