12

Without reinventing the wheel, what I can use to manage user sessions in a web application and being able to respond with JSON to ajax requests?

Is there some framework (made for example with Indy components or something like this)?

Note for bounty:

in practice it is enough for me to have a reply with a clear example of a server application that serves json. Somehow a Delphi example of the php example mentioned HERE. (without the DB part, I want to see the basics of what does it mean to send JSON. I have basic knowledge of TIdHTTPServer.)

UnDiUdin
  • 14,924
  • 39
  • 151
  • 249
  • A request is a request, does not mind if it is ajax or not on the client side. You may want to update your question to ask just for session management. – jachguate Dec 13 '10 at 18:34
  • 1
    @jachguate: Session management is just part of the request implementation. You'll have to parse the query, then retrieve the data, then create the JSON response. And AJAX introduces new specifications about the JSON format. – Arnaud Bouchez Dec 13 '10 at 18:37
  • @A.Bouchez: Can you tell me what is different in the json format when you serve it over an ajax request from what you serve if the request is not ajax? – jachguate Dec 14 '10 at 15:00
  • 1
    @jachquate: It depends on the UI components or the JavaScript code which will consume the JSON content. For instance, see http://synopse.info/forum/viewtopic.php?pid=97#p97 for diverse JSON layout (one ready for AJAX, with all property names, and one not expanded format, better for a Delphi client), and the link to Yahoo grid URI and JSON encoding expectations. – Arnaud Bouchez Dec 14 '10 at 16:05

6 Answers6

6

You can take a look at our Synopse SQLite3 Framework, which was just updated to version 1.11.

It serves the data in pure JSON, ready to be used in any AJAX application.

You can also easily create Services, more precisely Client-Server JSON RESTful Services. In this case, you can even not use SQLite3 for your data storage.

This framework is pure Open Source, compiles/run/is tested for Delphi 6 up to XE, is Unicode ready for all versions of Delphi (it uses UTF-8 internally).

By using this framework, you could be able to create easily also Delphi clients, using JSON data from the same server.

There is no internal User session handling yet. Because there are several way of implementing them, and, since our framework is RESTful, it's therefore stateless: no session is needed.

If you need it, I could easily add HTTP sessions using Cookies. What about the User authentication you are expecting?

Arnaud Bouchez
  • 42,305
  • 3
  • 71
  • 159
  • Thanks for the reply. What I am looking for it is a Delphi framework for creating a backend to a web application. I am planning to use Sencha Touch for the UI (and this is why I don't want to use things like Intraweb). I have lot of code that I can reuse, this is why I am looking for a Delphi backend (and moreover because it is the only language I am proficient at). The autentication I need is the classical User/Password, it is not a real DB autenthication, even if under the hood I use DB users for autenthication, but then all connections are done through a single user. So pooling is possible. – UnDiUdin Dec 15 '10 at 09:13
  • Do you think that framework will allow me to generate a web application that uses Sencha Touch (or any javascript framework) without suffering too much? (otherwise said: is there already a working application to check? Or which alternatives do you suggest for managing autenthication? – UnDiUdin Dec 15 '10 at 09:17
  • Sencha Touch belongs the same family as ExtJS. So for avoiding much "suffering", I'd recommend taking a look at ExtPascal or Raudus, which are dedicated to ExtJS: http://stackoverflow.com/questions/3022378/raudus-vs-extpascal-delphi-web-developement-alternatives-that-use-extjs But be aware of the ExtJS/SenchaTouch license, which is not Open Source for all uses. – Arnaud Bouchez Dec 16 '10 at 07:46
5

DelphiMVCFramework does this

Some notable features:

  • RESTful (RMM Level 3) compliant
  • Can be used in load balanced environment using Redis (http://Redis.io) [dev]
  • Fancy URL with parameter mappings
  • Specialied 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, XE7, XE8) and ISAPI dll
  • Integrated RESTClient Works with XE3, XE4, XE5, XE6, XE7 and XE8 Completely unit tested
  • There is a sample for each functionlities
  • There is a complete set of trainings about it, but the samples are included in the project Experimental support for IOCP [dev]
  • Server side generated pages using eLua (Embedded Lua) [removed soon]
  • Specific trainings are available (ask me for a date and a place)
  • Messaging extension using STOMP (beta)
  • Community driven (Facebook group https://www.facebook.com/groups/delphimvcframework)
  • Simple and documented
  • There are books that talk about the framework

Project web site: https://github.com/danieleteti/delphimvcframework

N.B. I'm the main developer

Daniele Teti
  • 1,764
  • 14
  • 20
5

Maybe this can help you:

REST Servers in Delphi XE Using DataSnap Whitepaper

Learn how to build REST servers using features available in Delphi XE, how to extend them with extra Delphi support code and how to take advantage of the jQuery library.

Marco Cantù

http://app.en25.com/e/er.aspx?s=608&lid=4414&elq=d428643420d2494581299418d9753feb

Toto
  • 1,360
  • 1
  • 16
  • 18
  • Thanks, this is very informative, I don't have time to install Delphi XE Enterprise trial (I have the professional) and run the examples by the end of bounty. Could you please summarize what I get "out of the box" with datasnap xe compared to create all from scratch with webbroker? I guess by reading titles of whitepape: sessions management, authentication and then? (I mean which are the advantages of datasnap xe in my particular case) – UnDiUdin Jun 01 '11 at 07:17
  • Basically in Datasnap if you have a function returning an object Datasnap will serve it automatically as json. Refer to OBJECTS AND MARSHALING on page 29 in the .pdf – Toto Jun 01 '11 at 10:14
  • Just two remarks: **1.** DataSnap is not included Professional Edition of Delphi. **2.** It probably still has [poor performance and stability](https://datasnapperformance.wordpress.com/2014/10/16/datasnap-performance-test-en/) compared to its Delphi based competitors and similar technologies not based on Delphi. – Peter Wolf Jun 27 '19 at 11:13
4

I would suggest Delphi on Rails, it is an open source REST/MVC/StateLess web framework.

http://code.google.com/p/delphionrails/

It use:

  • superobject JSON parser
  • UIB/Firebird JSON driver
  • Cairo for SVG, PDF, PNG rendering
  • LUA for scripting/template ...

It is able to serialize automatically Delphi data structures to JSON using the new RTTI introduced in Delphi 2010 & XE.

Henri Gourvest
  • 989
  • 8
  • 12
0

I would recommend Super Object Toolkit.

http://www.progdigy.com

Example Code:

procedure Share(ARequestInfo: TIdHTTPRequestInfo)
var
ReturnObject: ISuperObject;
begin
  ReturnObject := SO();
  ReturnObject.B['success'] := false;

  AResponseInfo.ContentType := 'application/json';
  AResponseInfo.ContentText := ReturnObject.AsJSon();
end;
0

Daraja HTTP Framework, which uses Indy internally and adds a high level API for "web application contexts" and request mappings, loosely inspired by the Servlet API.

If you already have experience with TIdHTTPServer, you can directly access and adjust the server component according to your needs.

For JSON, you may use the built-in JSON support in newer Delphi versions or a third-party library (e.g. JsonDataObjects).

Disclaimer: I am the developer of the framework

mjn
  • 36,362
  • 28
  • 176
  • 378