12
votes

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.)

6
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
@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
@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
@jachquate: It depends on the UI components or the JavaScript code which will consume the JSON content. For instance, see 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

6 Answers

6
votes

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?

5
votes

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

5
votes

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

4
votes

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.

0
votes

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
votes

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