Page 2 of 2 FirstFirst 1 2
Results 16 to 19 of 19

Thread: RAD server

  1. #16
    Senior Member EricLang's Avatar
    Join Date
    May 2002
    Location
    Holland
    Posts
    3,136
    Dat klinkt zo goed als ideaal.

  2. #17
    mov rax,marcov; push rax marcov's Avatar
    Join Date
    Apr 2004
    Location
    Ehv, Nl
    Posts
    9,840
    Waar is de json errorhandling voor het geval van mallformed jsoN?

  3. #18

    Even simpler

    It can even be easier (I include TEmployee definition for a more complete example).

    Code:
    [kbmMW_Root('employee',[mwrfIncludeOnlyTagged])] // Tells how TEmployee should be named and marshalled
    [kbmMW_Table('name:employee')]
    TEmployee = class
    private
      FID:kbmMWNullable<string>;
      FName:kbmMWNullable<string>;
      FAge:kbmMWNullable<integer>;
    public
      [kbmMW_Attribute('id')]   // When marshalled (serialized/deserialized), the field ID will be named id in the JSON/XML/YAML document. In the XML document it will be rendered as an attribute. 
      [kbmMW_Field('name:id, primary:true, generator:shortGuid',ftString,40)]
      property ID:kbmMWNullable<string> read FID write FID;
    
      [kbmMW_Attribute('name')]
      [kbmMW_Field('name:name',ftWideString,50)]
      property Name:kbmMWNullable<string> read FName write FName;
    
      [kbmMW_Attribute('age')]
      [kbmMW_Field('name:age',ftInteger)]
      property Age:kbmMWNullable<integer> read FAge write FAge;
    end;
    Basically one class definition contains all the relevant info for both being stored in a datastorage (database) via the ORM, and how to be marshalled (serialized/deserialized) to/from XML, JSON, YAML, BSON and MessagePack or alternatively to the internal kbmMW Object Notation format which in addition to XML, JSON etc. also can be convert to and from CSV format.

    ...

    Code:
        DmServer.ORM.CreateOrUpgradeTable(TEmployee);
    ...

    Code:
        [kbmMW_Rest('method:post, path:"employees"')]
        function AddEmployee([kbmMW_Rest('value:"body"')] const AEmployee: TEmployee): boolean;
    Code:
    function TKbmSalonManagerRestAPI.AddEmployee(const AEmployee: TEmployee): boolean;
    begin
        AEmployee.EmployeeID := kbmMWGenerateShortGUID;
        Result := DmServer.ORM.Insert(AEmployee);
    end;
    kbmMW will automatically dispose the TEmployee instance on exit of AddEmployee, unless you specifically tell it not to.


    best regards
    Kim/C4D

    Quote Originally Posted by luigi View Post
    Kbmmw is echt uitermate geschikt voor het schrijven van een REST server. Je kunt, als je dat wilt ook gebruik maken van het ingebouwde ORM, dan krijg je code als.

    Code:
        [kbmMW_Rest('method:post, path:"employees"')]
        function AddEmployee([kbmMW_Rest('value:"body"')] var AJSONEmployee: string): boolean;
    Code:
    function TKbmSalonManagerRestAPI.AddEmployee(var AJSONEmployee: string): boolean;
    var
      E: TEmployee;
    begin
      E := TEmployee.Create;
      try
        JsonToObject(AJSONEmployee, E);
        E.EmployeeID := kbmMWGenerateShortGUID;
        Result := DmServer.ORM.Insert(E);
      finally
        E.Free;
      end;
    end;

  4. #19
    Senior Member EricLang's Avatar
    Join Date
    May 2002
    Location
    Holland
    Posts
    3,136
    Thank you Kim.

Page 2 of 2 FirstFirst 1 2

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •