{"id":446,"date":"2011-01-18T00:42:55","date_gmt":"2011-01-18T08:42:55","guid":{"rendered":"http:\/\/www.andreanolanusse.com\/en\/?p=446"},"modified":"2011-02-02T02:12:00","modified_gmt":"2011-02-02T10:12:00","slug":"handling-datasnap-rest-server-methods-through-php","status":"publish","type":"post","link":"http:\/\/www.andreanolanusse.com\/en\/handling-datasnap-rest-server-methods-through-php\/","title":{"rendered":"Handling DataSnap (REST) server methods through PHP"},"content":{"rendered":"<p>Create PHP applications to connect to DataSnap <a href=\"http:\/\/en.wikipedia.org\/wiki\/Representational_State_Transfer\" target=\"_blank\"><strong>REST<\/strong><\/a> servers is relatively simple since the RadPHP includes a wizard that generates the proxy classes in PHP, but as PHP is a dynamic language and is not strongly typed, it opens the possibility for errors when we execute the server methods, in addition to that REST calls always returns a JSON object, but if you are aware how REST, JSON and DataSnap works it became easy to manage.<\/p>\n<p>Consider the following scenario where you have an authentication method that returns TRUE or FALSE, of course you must be thinking that in case of error the method will always return false, this is not necessarily true and I&#8217;ll explain next.<\/p>\n<p>Assuming you have generated the proxy class in PHP through <a href=\"http:\/\/www.embarcadero.com\/products\/radphp\" target=\"_blank\"><strong>RadPHP<\/strong><\/a> IDE, you have what you need to execute the DataSnap business logic from PHP code, when the server method is executed from REST server it will always return an JSON object.<\/p>\n<p>The RadPHP proxy generator wizard will create a datamodule which containing the DSRestConnection component, this component has the necessarily information to connect to the server, like: Host, Port, Username and Password.<\/p>\n<p>The following code execute the server method TUser.isValidUser having username and password as parameter, if the server method returns an instance of DSObject it means the method was executed successfully and it will have a DSObject-&gt;result property, in this case TRUE or FALSE, in case the method fails for some reason or raise an EXCEPTION DSObject will not be returned and you will have to check the property ERROR to get the error message.<\/p>\n<pre class=\"brush: php\">type\r\n   global $ClientModuleDataModule1;\r\n   $conninfo = $ClientModuleDataModule1-&gt;DSRestConnection1-&gt;ConnectionInfo;\r\n\r\n   $user = new TUser($conninfo);\r\n\r\n   $valid = $user-&gt;IsValidUser($this-&gt;edUserName-&gt;Text, $this-&gt;edPassword-&gt;Text);\r\n\r\n   if($valid instanceof DSObject)\r\n   {\r\n      if($valid-&gt;result)\r\n      {\r\n         setcookie('loginid', $this-&gt;edUserName-&gt;Text);\r\n         redirect(\"Main.php\");\r\n      }\r\n      else\r\n      {\r\n         $this-&gt;Button1-&gt;Caption = \"Username\/Password invalid\";\r\n      }\r\n   }\r\n   else\r\n   {\r\n      $this-&gt;Button1-&gt;Caption = $valid-&gt;error;\r\n   }<\/pre>\n<p>In the examples of RAD Studio XE available at sourceforge you can download the full PHP code used on this post, as well the Delphi DataSnap server, <a href=\"https:\/\/radstudiodemos.svn.sourceforge.net\/svnroot\/radstudiodemos\/branches\/RadStudio_XE\/DataSnapXE\/\" target=\"_blank\">download here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Create PHP applications to connect to DataSnap REST servers is relatively simple since the RadPHP includes a wizard that generates the proxy classes in PHP, but as PHP is a dynamic language and is not strongly typed, it opens the possibility for errors when we execute the server methods, in addition to that REST calls [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":447,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_s2mail":"","footnotes":""},"categories":[89],"tags":[21,38],"class_list":["post-446","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-radphp","tag-datasnap","tag-radphp"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Handling DataSnap (REST) server methods through PHP | Andreano Lanusse | Technology and Software Development<\/title>\n<meta name=\"description\" content=\"Create PHP applications to connect to DataSnap REST servers is relatively simple since the RadPHP includes a wizard that generates the proxy classes in\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.andreanolanusse.com\/en\/handling-datasnap-rest-server-methods-through-php\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Handling DataSnap (REST) server methods through PHP | Andreano Lanusse | Technology and Software Development\" \/>\n<meta property=\"og:description\" content=\"Create PHP applications to connect to DataSnap REST servers is relatively simple since the RadPHP includes a wizard that generates the proxy classes in\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.andreanolanusse.com\/en\/handling-datasnap-rest-server-methods-through-php\/\" \/>\n<meta property=\"og:site_name\" content=\"Andreano Lanusse | Technology and Software Development\" \/>\n<meta property=\"article:published_time\" content=\"2011-01-18T08:42:55+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2011-02-02T10:12:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.andreanolanusse.com\/en\/wp-content\/uploads\/2011\/01\/Icon_DelphiPHP.png\" \/>\n\t<meta property=\"og:image:width\" content=\"279\" \/>\n\t<meta property=\"og:image:height\" content=\"279\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Andreano Lanusse\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Andreano Lanusse\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.andreanolanusse.com\/en\/handling-datasnap-rest-server-methods-through-php\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.andreanolanusse.com\/en\/handling-datasnap-rest-server-methods-through-php\/\"},\"author\":{\"name\":\"Andreano Lanusse\",\"@id\":\"http:\/\/www.andreanolanusse.com\/en\/#\/schema\/person\/b51fdf99c01fcd6ae0a5ae894c23837b\"},\"headline\":\"Handling DataSnap (REST) server methods through PHP\",\"datePublished\":\"2011-01-18T08:42:55+00:00\",\"dateModified\":\"2011-02-02T10:12:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.andreanolanusse.com\/en\/handling-datasnap-rest-server-methods-through-php\/\"},\"wordCount\":304,\"commentCount\":1,\"publisher\":{\"@id\":\"http:\/\/www.andreanolanusse.com\/en\/#\/schema\/person\/b51fdf99c01fcd6ae0a5ae894c23837b\"},\"image\":{\"@id\":\"https:\/\/www.andreanolanusse.com\/en\/handling-datasnap-rest-server-methods-through-php\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/www.andreanolanusse.com\/en\/wp-content\/uploads\/2011\/01\/Icon_DelphiPHP.png\",\"keywords\":[\"DataSnap\",\"PHP\"],\"articleSection\":[\"PHP\"],\"inLanguage\":\"en\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.andreanolanusse.com\/en\/handling-datasnap-rest-server-methods-through-php\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.andreanolanusse.com\/en\/handling-datasnap-rest-server-methods-through-php\/\",\"url\":\"https:\/\/www.andreanolanusse.com\/en\/handling-datasnap-rest-server-methods-through-php\/\",\"name\":\"Handling DataSnap (REST) server methods through PHP | Andreano Lanusse | Technology and Software Development\",\"isPartOf\":{\"@id\":\"http:\/\/www.andreanolanusse.com\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.andreanolanusse.com\/en\/handling-datasnap-rest-server-methods-through-php\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.andreanolanusse.com\/en\/handling-datasnap-rest-server-methods-through-php\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/www.andreanolanusse.com\/en\/wp-content\/uploads\/2011\/01\/Icon_DelphiPHP.png\",\"datePublished\":\"2011-01-18T08:42:55+00:00\",\"dateModified\":\"2011-02-02T10:12:00+00:00\",\"description\":\"Create PHP applications to connect to DataSnap REST servers is relatively simple since the RadPHP includes a wizard that generates the proxy classes in\",\"breadcrumb\":{\"@id\":\"https:\/\/www.andreanolanusse.com\/en\/handling-datasnap-rest-server-methods-through-php\/#breadcrumb\"},\"inLanguage\":\"en\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.andreanolanusse.com\/en\/handling-datasnap-rest-server-methods-through-php\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en\",\"@id\":\"https:\/\/www.andreanolanusse.com\/en\/handling-datasnap-rest-server-methods-through-php\/#primaryimage\",\"url\":\"http:\/\/www.andreanolanusse.com\/en\/wp-content\/uploads\/2011\/01\/Icon_DelphiPHP.png\",\"contentUrl\":\"http:\/\/www.andreanolanusse.com\/en\/wp-content\/uploads\/2011\/01\/Icon_DelphiPHP.png\",\"width\":279,\"height\":279},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.andreanolanusse.com\/en\/handling-datasnap-rest-server-methods-through-php\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/www.andreanolanusse.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Handling DataSnap (REST) server methods through PHP\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/www.andreanolanusse.com\/en\/#website\",\"url\":\"http:\/\/www.andreanolanusse.com\/en\/\",\"name\":\"Andreano Lanusse | Technology and Software Development\",\"description\":\"Where Andreano Lanusse talk about technology, software development, programming techniques, databases, games and more through articles, tutorials and videos\",\"publisher\":{\"@id\":\"http:\/\/www.andreanolanusse.com\/en\/#\/schema\/person\/b51fdf99c01fcd6ae0a5ae894c23837b\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/www.andreanolanusse.com\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"http:\/\/www.andreanolanusse.com\/en\/#\/schema\/person\/b51fdf99c01fcd6ae0a5ae894c23837b\",\"name\":\"Andreano Lanusse\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en\",\"@id\":\"http:\/\/www.andreanolanusse.com\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/49ab23ef70c249c0cb3469f14ef07edc?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/49ab23ef70c249c0cb3469f14ef07edc?s=96&d=mm&r=g\",\"caption\":\"Andreano Lanusse\"},\"logo\":{\"@id\":\"http:\/\/www.andreanolanusse.com\/en\/#\/schema\/person\/image\/\"},\"description\":\"Andreano Lanusse is an expert and enthusiastic on software development industry, at Embarcadero he is focused on helping to make sure the products being developed meet the expectations of Embarcadero's customers, as well as defining market strategies for Latin America. Today as Latin Lead Evangelist he spends great deal of time in developer conferences, tradeshows, user group, and visiting customers throughout Latin America. Before Embarcadero, he worked 13 years for Borland, Andreano has worked as Support Coordinator, Engineer, Product Manager, including Product Line Sales Manager, where was responsible to manage the relationship with Brazil developer community, also has worked as Principal Consultant for Borland Consulting Services on the development and management of critical applications. He previously served as Chief Architect for USS Solu\u00e7\u00f5es Gerenciadas (now USS Tempo). Andreano holds a bachelor's degree in Business Administration Marketing Emphasis from Sumare Institute, MBA in Project Management from FGV, certification in Microsoft products, all Borland ALM products, and all CodeGear product line.\",\"sameAs\":[\"http:\/\/www.andreanolanusse.com\",\"https:\/\/x.com\/andreanolanusse\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Handling DataSnap (REST) server methods through PHP | Andreano Lanusse | Technology and Software Development","description":"Create PHP applications to connect to DataSnap REST servers is relatively simple since the RadPHP includes a wizard that generates the proxy classes in","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.andreanolanusse.com\/en\/handling-datasnap-rest-server-methods-through-php\/","og_locale":"en_US","og_type":"article","og_title":"Handling DataSnap (REST) server methods through PHP | Andreano Lanusse | Technology and Software Development","og_description":"Create PHP applications to connect to DataSnap REST servers is relatively simple since the RadPHP includes a wizard that generates the proxy classes in","og_url":"https:\/\/www.andreanolanusse.com\/en\/handling-datasnap-rest-server-methods-through-php\/","og_site_name":"Andreano Lanusse | Technology and Software Development","article_published_time":"2011-01-18T08:42:55+00:00","article_modified_time":"2011-02-02T10:12:00+00:00","og_image":[{"width":279,"height":279,"url":"https:\/\/www.andreanolanusse.com\/en\/wp-content\/uploads\/2011\/01\/Icon_DelphiPHP.png","type":"image\/png"}],"author":"Andreano Lanusse","twitter_misc":{"Written by":"Andreano Lanusse","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.andreanolanusse.com\/en\/handling-datasnap-rest-server-methods-through-php\/#article","isPartOf":{"@id":"https:\/\/www.andreanolanusse.com\/en\/handling-datasnap-rest-server-methods-through-php\/"},"author":{"name":"Andreano Lanusse","@id":"http:\/\/www.andreanolanusse.com\/en\/#\/schema\/person\/b51fdf99c01fcd6ae0a5ae894c23837b"},"headline":"Handling DataSnap (REST) server methods through PHP","datePublished":"2011-01-18T08:42:55+00:00","dateModified":"2011-02-02T10:12:00+00:00","mainEntityOfPage":{"@id":"https:\/\/www.andreanolanusse.com\/en\/handling-datasnap-rest-server-methods-through-php\/"},"wordCount":304,"commentCount":1,"publisher":{"@id":"http:\/\/www.andreanolanusse.com\/en\/#\/schema\/person\/b51fdf99c01fcd6ae0a5ae894c23837b"},"image":{"@id":"https:\/\/www.andreanolanusse.com\/en\/handling-datasnap-rest-server-methods-through-php\/#primaryimage"},"thumbnailUrl":"http:\/\/www.andreanolanusse.com\/en\/wp-content\/uploads\/2011\/01\/Icon_DelphiPHP.png","keywords":["DataSnap","PHP"],"articleSection":["PHP"],"inLanguage":"en","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.andreanolanusse.com\/en\/handling-datasnap-rest-server-methods-through-php\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.andreanolanusse.com\/en\/handling-datasnap-rest-server-methods-through-php\/","url":"https:\/\/www.andreanolanusse.com\/en\/handling-datasnap-rest-server-methods-through-php\/","name":"Handling DataSnap (REST) server methods through PHP | Andreano Lanusse | Technology and Software Development","isPartOf":{"@id":"http:\/\/www.andreanolanusse.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.andreanolanusse.com\/en\/handling-datasnap-rest-server-methods-through-php\/#primaryimage"},"image":{"@id":"https:\/\/www.andreanolanusse.com\/en\/handling-datasnap-rest-server-methods-through-php\/#primaryimage"},"thumbnailUrl":"http:\/\/www.andreanolanusse.com\/en\/wp-content\/uploads\/2011\/01\/Icon_DelphiPHP.png","datePublished":"2011-01-18T08:42:55+00:00","dateModified":"2011-02-02T10:12:00+00:00","description":"Create PHP applications to connect to DataSnap REST servers is relatively simple since the RadPHP includes a wizard that generates the proxy classes in","breadcrumb":{"@id":"https:\/\/www.andreanolanusse.com\/en\/handling-datasnap-rest-server-methods-through-php\/#breadcrumb"},"inLanguage":"en","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.andreanolanusse.com\/en\/handling-datasnap-rest-server-methods-through-php\/"]}]},{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/www.andreanolanusse.com\/en\/handling-datasnap-rest-server-methods-through-php\/#primaryimage","url":"http:\/\/www.andreanolanusse.com\/en\/wp-content\/uploads\/2011\/01\/Icon_DelphiPHP.png","contentUrl":"http:\/\/www.andreanolanusse.com\/en\/wp-content\/uploads\/2011\/01\/Icon_DelphiPHP.png","width":279,"height":279},{"@type":"BreadcrumbList","@id":"https:\/\/www.andreanolanusse.com\/en\/handling-datasnap-rest-server-methods-through-php\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/www.andreanolanusse.com\/en\/"},{"@type":"ListItem","position":2,"name":"Handling DataSnap (REST) server methods through PHP"}]},{"@type":"WebSite","@id":"http:\/\/www.andreanolanusse.com\/en\/#website","url":"http:\/\/www.andreanolanusse.com\/en\/","name":"Andreano Lanusse | Technology and Software Development","description":"Where Andreano Lanusse talk about technology, software development, programming techniques, databases, games and more through articles, tutorials and videos","publisher":{"@id":"http:\/\/www.andreanolanusse.com\/en\/#\/schema\/person\/b51fdf99c01fcd6ae0a5ae894c23837b"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/www.andreanolanusse.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en"},{"@type":["Person","Organization"],"@id":"http:\/\/www.andreanolanusse.com\/en\/#\/schema\/person\/b51fdf99c01fcd6ae0a5ae894c23837b","name":"Andreano Lanusse","image":{"@type":"ImageObject","inLanguage":"en","@id":"http:\/\/www.andreanolanusse.com\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/49ab23ef70c249c0cb3469f14ef07edc?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/49ab23ef70c249c0cb3469f14ef07edc?s=96&d=mm&r=g","caption":"Andreano Lanusse"},"logo":{"@id":"http:\/\/www.andreanolanusse.com\/en\/#\/schema\/person\/image\/"},"description":"Andreano Lanusse is an expert and enthusiastic on software development industry, at Embarcadero he is focused on helping to make sure the products being developed meet the expectations of Embarcadero's customers, as well as defining market strategies for Latin America. Today as Latin Lead Evangelist he spends great deal of time in developer conferences, tradeshows, user group, and visiting customers throughout Latin America. Before Embarcadero, he worked 13 years for Borland, Andreano has worked as Support Coordinator, Engineer, Product Manager, including Product Line Sales Manager, where was responsible to manage the relationship with Brazil developer community, also has worked as Principal Consultant for Borland Consulting Services on the development and management of critical applications. He previously served as Chief Architect for USS Solu\u00e7\u00f5es Gerenciadas (now USS Tempo). Andreano holds a bachelor's degree in Business Administration Marketing Emphasis from Sumare Institute, MBA in Project Management from FGV, certification in Microsoft products, all Borland ALM products, and all CodeGear product line.","sameAs":["http:\/\/www.andreanolanusse.com","https:\/\/x.com\/andreanolanusse"]}]}},"_links":{"self":[{"href":"http:\/\/www.andreanolanusse.com\/en\/wp-json\/wp\/v2\/posts\/446","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.andreanolanusse.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.andreanolanusse.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.andreanolanusse.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.andreanolanusse.com\/en\/wp-json\/wp\/v2\/comments?post=446"}],"version-history":[{"count":0,"href":"http:\/\/www.andreanolanusse.com\/en\/wp-json\/wp\/v2\/posts\/446\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.andreanolanusse.com\/en\/wp-json\/wp\/v2\/media\/447"}],"wp:attachment":[{"href":"http:\/\/www.andreanolanusse.com\/en\/wp-json\/wp\/v2\/media?parent=446"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.andreanolanusse.com\/en\/wp-json\/wp\/v2\/categories?post=446"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.andreanolanusse.com\/en\/wp-json\/wp\/v2\/tags?post=446"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}