Instantly expose a data table as JSON/REST with Delphi.

RESTDebug

[NEW UPDATE] I’ve replaced this component with a re-write named “deREST” – find out more here: http://chapmanworld.com/2018/07/21/instantly-expose-a-table-as-a-rest-endpoint-again/

Since my skill sprint on JSON/REST services in Delphi and C++ builder back in February, one thing has been nagging on my mind. The code that I wrote for that skill sprint was written specifically to expose one particular database table, but it was almost generic enough that it could expose any database table. So why don’t I write a component for exposing tables as JSON/REST endpoints?

Well, for the past two or three days I’ve been working on just such a component, and I’d now like to demonstrate for you, just how easy it can be to create a JSON/REST service application using it. The server side component, when placed into a WebBroker application module, automatically adds an endpoint, and you simply need to bind the component up to a database connection to make it function.

[Video Removed] – I’ll leave the download here for anyone still using it, but I’ve replaced this component: http://chapmanworld.com/2018/07/21/instantly-expose-a-table-as-a-rest-endpoint-again/

DISCLAIMER

I must apologize for needing a disclaimer, but I’m sure you’ll understand why it’s necessary…

Before I hand you the source code for this component, and demonstrate it’s use, I’d like to make one thing very clear. I wrote this component (actually two components) for no other purpose than to demonstrate that it could be done. I wouldn’t want you to think that this code is in any way safe for commercial use. I do provide these components free of charge, and welcome you to use them for any purpose, however, as it is not commercial grade code I will not be held responsible if you use it and incur damages. I would be happy to entertain volunteers that wish to review and enhance the code, add unit tests, add injection protection, authentication and so on, however, I will not personally be investing in this code any further. Okay?

The source:

Okay, so the source code is may be downloaded here:  JCRUD

Thanks for reading!

 

Facebooktwitterredditpinterestlinkedintumblrmail

15 thoughts on “Instantly expose a data table as JSON/REST with Delphi.”

  1. I done little bit changes, but when I got $.ajax command got in my web client ( html pages with jquery ) server response was with error : Failed to load http://192.168.0.138:8787/….: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘null’ is therefore not allowed access. The response had HTTP status code 400.

    What have do I do ? help me..
    for mssql server work very well.When I write url to web client rersponse JSON is ok.

    thank you

  2. Hi,

    I’m trying to create small application using 1 table as your short tutorial, server running tested with browser 3 record show up, but when I try to connect the client always get error “no peer with the interface with guid {xxxx}”.

    Is there any hints for this error?

    Thanks,
    Tegoeh

  3. really good component.

    I have a qustion about , how can i make a login form useing this component ?
    i create another table in DB and called it ‘Login’ and JCRUDRESTFireDACServer (Endpoint (login) and key field (ID)) >> working good at webbrowser
    in Client
    i add another TJCRUDRestClientDataset (Endpoint (login))
    I insert this code
    if Login.Active then begin
    Login.Insert;
    Login.FieldByName[‘ID’] :=Edit1.Text;
    Login.FieldByName[‘User’] :=Edit2.Text;
    showmessage (‘Done’);
    Login.Post;

    end;

    And I show this message :
    —————————
    Error
    —————————
    HTTP/1.1 500 Internal Server Error.
    —————————
    OK
    —————————

Leave a Comment