<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>REST &#8211; Xojo Programming Blog</title>
	<atom:link href="https://blog.xojo.com/tag/rest/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.xojo.com</link>
	<description>Blog about the Xojo programming language and IDE</description>
	<lastBuildDate>Mon, 18 Aug 2025 20:38:25 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>Xojo Web Rescues a .NET Project</title>
		<link>https://blog.xojo.com/2024/10/23/xojo-web-rescues-a-net-project/</link>
		
		<dc:creator><![CDATA[Wayne Golding]]></dc:creator>
		<pubDate>Wed, 23 Oct 2024 16:40:14 +0000</pubDate>
				<category><![CDATA[Guest Post]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Encryption]]></category>
		<category><![CDATA[Rapid Application Development]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[URLConnection]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Xojo Programming Language]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=13909</guid>

					<description><![CDATA[I had a call recently from a customer whose upstream supplier informed them that they would not be accepting anything less than TLS 1.2 encryption.&#8230;]]></description>
										<content:encoded><![CDATA[
<p>I had a call recently from a customer whose upstream supplier informed them that they would not be accepting anything less than TLS 1.2 encryption. The customer’s application is written using .NET 1.1 (they are testing a new version but aren’t ready to deploy to production just yet). Their supplier insisted on a 1-week time limit. Can I help?</p>



<p>My answer was, of course, “Let me have a look and get back to you.”</p>



<p>I went to my favourite dev tool, Xojo, and went through the process of developing a solution.&nbsp;The connection is a REST API, so I’ll start with a web project and use the HandleURL event. And I’ll use a URLConnection to pass on the request.&nbsp; Wait … could it be that simple?</p>



<pre class="wp-block-code"><code>Function HandleURL(request As WebRequest, response As WebResponse) Handles HandleURL as Boolean

  // Create the outbound connection
  Var connector As New URLConnection
 
  // Copy the content of the request
  connector.SetRequestContent(request.Body, request.MIMEType)

  // Send the request
  Var result As String
  Try
    result = connector.SendSync("POST", kAddress + request.Path)
  Catch err As RuntimeException
    // Catch DNS, Certificate &amp; Timeout errors
    response.Status = 500
    response.Write(err.Message)
    Return True
  End

  // Return the result of the request
  response.Status = connector.HTTPStatusCode
  response.Write(result)

  Return True

End Function</code></pre>



<p>The answer is, &#8220;Yes!&#8221;&nbsp; This is all the code in the entire project.</p>



<p>You will notice that there is no security, but in this instance that is fine as the virtual machine is running this is on the same network as the client server and the firewall is configured to only allow connections from that server.</p>



<p>After processing over 60 thousand requests, memory use is 7.3MB and never exceeded 13MB.&nbsp;CPU usage was at the maximum 1.5%.</p>



<p>Even after using Xojo for 20 years this still blows my mind.</p>



<p><em>Wayne Golding has been a Xojo developer since 2005 and is a Xojo MVP. He operates the IT Company <a href="http://www.axisdirect.nz">Axis Direct Ltd </a>which primarily develops applications using Xojo that integrate with Xero www.xero.com. Wayne’s hobby is robotics where he uses Xojo to build applications for his Raspberry Pi, often implementing IoT for remote control.</em></p>



<ul class="wp-block-social-links has-normal-icon-size is-content-justification-center is-layout-flex wp-container-core-social-links-is-layout-16018d1d wp-block-social-links-is-layout-flex"><li class="wp-social-link wp-social-link-facebook  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://www.facebook.com/goxojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M12 2C6.5 2 2 6.5 2 12c0 5 3.7 9.1 8.4 9.9v-7H7.9V12h2.5V9.8c0-2.5 1.5-3.9 3.8-3.9 1.1 0 2.2.2 2.2.2v2.5h-1.3c-1.2 0-1.6.8-1.6 1.6V12h2.8l-.4 2.9h-2.3v7C18.3 21.1 22 17 22 12c0-5.5-4.5-10-10-10z"></path></svg><span class="wp-block-social-link-label screen-reader-text">Facebook</span></a></li>

<li class="wp-social-link wp-social-link-x  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://x.com/xojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M13.982 10.622 20.54 3h-1.554l-5.693 6.618L8.745 3H3.5l6.876 10.007L3.5 21h1.554l6.012-6.989L15.868 21h5.245l-7.131-10.378Zm-2.128 2.474-.697-.997-5.543-7.93H8l4.474 6.4.697.996 5.815 8.318h-2.387l-4.745-6.787Z" /></svg><span class="wp-block-social-link-label screen-reader-text">X</span></a></li>

<li class="wp-social-link wp-social-link-linkedin  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://www.linkedin.com/company/xojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M19.7,3H4.3C3.582,3,3,3.582,3,4.3v15.4C3,20.418,3.582,21,4.3,21h15.4c0.718,0,1.3-0.582,1.3-1.3V4.3 C21,3.582,20.418,3,19.7,3z M8.339,18.338H5.667v-8.59h2.672V18.338z M7.004,8.574c-0.857,0-1.549-0.694-1.549-1.548 c0-0.855,0.691-1.548,1.549-1.548c0.854,0,1.547,0.694,1.547,1.548C8.551,7.881,7.858,8.574,7.004,8.574z M18.339,18.338h-2.669 v-4.177c0-0.996-0.017-2.278-1.387-2.278c-1.389,0-1.601,1.086-1.601,2.206v4.249h-2.667v-8.59h2.559v1.174h0.037 c0.356-0.675,1.227-1.387,2.526-1.387c2.703,0,3.203,1.779,3.203,4.092V18.338z"></path></svg><span class="wp-block-social-link-label screen-reader-text">LinkedIn</span></a></li>

<li class="wp-social-link wp-social-link-github  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://github.com/topics/xojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M12,2C6.477,2,2,6.477,2,12c0,4.419,2.865,8.166,6.839,9.489c0.5,0.09,0.682-0.218,0.682-0.484 c0-0.236-0.009-0.866-0.014-1.699c-2.782,0.602-3.369-1.34-3.369-1.34c-0.455-1.157-1.11-1.465-1.11-1.465 c-0.909-0.62,0.069-0.608,0.069-0.608c1.004,0.071,1.532,1.03,1.532,1.03c0.891,1.529,2.341,1.089,2.91,0.833 c0.091-0.647,0.349-1.086,0.635-1.337c-2.22-0.251-4.555-1.111-4.555-4.943c0-1.091,0.39-1.984,1.03-2.682 C6.546,8.54,6.202,7.524,6.746,6.148c0,0,0.84-0.269,2.75,1.025C10.295,6.95,11.15,6.84,12,6.836 c0.85,0.004,1.705,0.114,2.504,0.336c1.909-1.294,2.748-1.025,2.748-1.025c0.546,1.376,0.202,2.394,0.1,2.646 c0.64,0.699,1.026,1.591,1.026,2.682c0,3.841-2.337,4.687-4.565,4.935c0.359,0.307,0.679,0.917,0.679,1.852 c0,1.335-0.012,2.415-0.012,2.741c0,0.269,0.18,0.579,0.688,0.481C19.138,20.161,22,16.416,22,12C22,6.477,17.523,2,12,2z"></path></svg><span class="wp-block-social-link-label screen-reader-text">GitHub</span></a></li>

<li class="wp-social-link wp-social-link-youtube  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://www.youtube.com/c/XojoInc" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M21.8,8.001c0,0-0.195-1.378-0.795-1.985c-0.76-0.797-1.613-0.801-2.004-0.847c-2.799-0.202-6.997-0.202-6.997-0.202 h-0.009c0,0-4.198,0-6.997,0.202C4.608,5.216,3.756,5.22,2.995,6.016C2.395,6.623,2.2,8.001,2.2,8.001S2,9.62,2,11.238v1.517 c0,1.618,0.2,3.237,0.2,3.237s0.195,1.378,0.795,1.985c0.761,0.797,1.76,0.771,2.205,0.855c1.6,0.153,6.8,0.201,6.8,0.201 s4.203-0.006,7.001-0.209c0.391-0.047,1.243-0.051,2.004-0.847c0.6-0.607,0.795-1.985,0.795-1.985s0.2-1.618,0.2-3.237v-1.517 C22,9.62,21.8,8.001,21.8,8.001z M9.935,14.594l-0.001-5.62l5.404,2.82L9.935,14.594z"></path></svg><span class="wp-block-social-link-label screen-reader-text">YouTube</span></a></li></ul>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Webinar Follow-Up: Using Xojo to Develop NetSuite iOS Apps</title>
		<link>https://blog.xojo.com/2024/01/29/webinar-follow-up-using-xojo-to-develop-netsuite-ios-apps/</link>
		
		<dc:creator><![CDATA[Tim Dietrich]]></dc:creator>
		<pubDate>Mon, 29 Jan 2024 16:00:00 +0000</pubDate>
				<category><![CDATA[Community]]></category>
		<category><![CDATA[Guest Post]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Multi-Platform Development]]></category>
		<category><![CDATA[NetSuite]]></category>
		<category><![CDATA[Rapid Application Development]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Xojo Programming Language]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=12515</guid>

					<description><![CDATA[Last week, I presented the second in a series of Xojo / NetSuite webinars, Using Xojo to Develop NetSuite iOS Apps. You can watch that webinar here. During the webinar, I demonstrated a Xojo-based iOS mobile app that integrates with NetSuite. This blog post is a follow-up to the webinar.]]></description>
										<content:encoded><![CDATA[
<p>Last week, I presented the second in a series of Xojo / NetSuite webinars, Using Xojo to Develop NetSuite iOS Apps. You can watch that webinar <a href="https://youtu.be/tXbaAnRHnGU">here</a>. During the webinar, I demonstrated a Xojo-based iOS mobile app that integrates with NetSuite. This blog post is a follow-up to the webinar.</p>



<h3 class="wp-block-heading"><strong>Downloading the Xojo Project</strong></h3>



<p>The Xojo project that I demonstrated can be downloaded <a href="https://tdietrich-opensource.s3.amazonaws.com/Xojo/Xojo%20NetSuite%20iOS%20Demo%20-%2020240124.01.zip" target="_blank" rel="noreferrer noopener">here</a>. In the zip file, you’ll find the Xojo project file and a “Readme” file. The Readme file includes step-by-step instructions on setting up SuiteTalk REST, a custom NetSuite role, an integration record, and more.</p>



<h3 class="wp-block-heading"><strong>The SuiteQL Query</strong></h3>



<p>During the webinar, I spent some time discussing the SuiteQL query that&#8217;s used to lookup items based on the keywords that a user enters. I mentioned that there&#8217;s a lot of variation between NetSuite instances, both in terms of how they&#8217;re configured and customized. That makes NetSuite development both challenging and interesting. </p>



<p>As a result of the variation between NetSuite instances, you may need to modify the SuiteQL query based on how your NetSuite instance is configured. In the Xojo project, you&#8217;ll find that the query is stored as a constant named &#8220;SuiteQLQuery,&#8221; and it&#8217;s an attribute of the ListView screen.</p>



<p>The query uses the REGEXP_LIKE condition, which I discussed recently in this <a href="https://timdietrich.me/blog/netsuite-suiteql-regexp-like-keyword-searches/">blog post</a>. If you&#8217;re not already familiar with REGEXP_LIKE, then you might want to read up on it. Also, in the query I&#8217;m using the TO_CHAR function to format the &#8220;first column Base Price&#8221; as currency. Specifically, in the query, you&#8217;ll see this: TO_CHAR ( COALESCE( MAX( Price ), 0 ), &#8216;fmL99G999D00&#8217; ). If you&#8217;d like to learn more about the TO_CHAR function and the format model modifiers that it supports, visit: <a href="https://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements004.htm#SQLRF00216">https://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements004.htm#SQLRF00216</a></p>



<h3 class="wp-block-heading"><strong>Our Next Webinar</strong></h3>



<p>Our next Xojo / NetSuite webinar will be held on Thursday, February 22nd at 1PM CT (US). I&#8217;ll demonstrate how you can use Xojo to develop a Web app that integrates with NetSuite. To signup, please visit Xojo&#8217;s <a href="https://xojo.com/resources/webinar.php">Webinar</a> page. And finally, I want to thank everyone that attended the webinar, as well as Geoff and the entire Xojo team for the opportunity to present.</p>



<p><em>Tim Dietrich develops custom software for businesses that are running on NetSuite. He makes extensive use of Xojo to develop mobile, desktop, Web apps, and more &#8211; all of which integrate seamlessly with NetSuite. To learn more, visit: https://timdietrich.me</em></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Webinar Follow-Up: Using Xojo to Develop NetSuite Android Apps</title>
		<link>https://blog.xojo.com/2023/12/19/webinar-follow-up-using-xojo-to-develop-netsuite-android-apps/</link>
		
		<dc:creator><![CDATA[Tim Dietrich]]></dc:creator>
		<pubDate>Tue, 19 Dec 2023 22:06:09 +0000</pubDate>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Community]]></category>
		<category><![CDATA[Guest Post]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Android Design Extensions]]></category>
		<category><![CDATA[Multi-Platform Development]]></category>
		<category><![CDATA[NetSuite]]></category>
		<category><![CDATA[Rapid Application Development]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Xojo Programming Language]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=12462</guid>

					<description><![CDATA[Last week I was thrilled to present Xojo's "Using Xojo to Develop NetSuite Android Apps" webinar. This blog post is intended as a follow-up to that webinar. I hope to provide some additional information that we didn't have time to cover, answer some of the questions that came up during and after the webinar, and also provide a link to the Xojo project that we created during the webinar.]]></description>
										<content:encoded><![CDATA[
<p>Last week I was thrilled to present Xojo&#8217;s &#8220;Using Xojo to Develop NetSuite Android Apps&#8221; webinar (<a href="https://youtu.be/sPOha9-VQRk">watch the webinar</a>). I want to thank everyone who attended, as well as Geoff and the entire Xojo team for the opportunity. It&#8217;s always nice to be able to introduce new developers to the Xojo platform.</p>



<p>This blog post is intended as a follow-up to that webinar. In it, I hope to provide some additional information that we didn&#8217;t have time to cover, answer some of the questions that came up during and after the webinar, and also provide a link to the Xojo project that we created during the webinar.</p>



<h3 class="wp-block-heading">Downloading the Xojo Project</h3>



<p>The Xojo project that we developed during the webinar is available for download <a href="https://tdietrich-opensource.s3.amazonaws.com/Xojo/Xojo%20NetSuite%20Android%20Demo%20-%2020231219.01.zip">here</a>. In the zip file, you&#8217;ll find the project and a &#8220;Readme&#8221; file that includes instructions on how to set things up (including SuiteTalk REST, a custom NetSuite role, an integration record, etc).</p>



<figure class="wp-block-image size-large is-style-default"><img fetchpriority="high" decoding="async" width="1024" height="758" src="https://blog.xojo.com/wp-content/uploads/2023/12/screen-shot-of-the-Xojo-project-file-1024x758.png" alt="A screen shot of the Xojo project file." class="wp-image-12473" srcset="https://blog.xojo.com/wp-content/uploads/2023/12/screen-shot-of-the-Xojo-project-file-1024x758.png 1024w, https://blog.xojo.com/wp-content/uploads/2023/12/screen-shot-of-the-Xojo-project-file-300x222.png 300w, https://blog.xojo.com/wp-content/uploads/2023/12/screen-shot-of-the-Xojo-project-file-768x568.png 768w, https://blog.xojo.com/wp-content/uploads/2023/12/screen-shot-of-the-Xojo-project-file-1536x1136.png 1536w, https://blog.xojo.com/wp-content/uploads/2023/12/screen-shot-of-the-Xojo-project-file-2048x1515.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>My advice is to download the project, setup NetSuite, and run the project. Then look at how the project was built -the screens, methods, and so on. After you&#8217;re familiar with the project file, experiment with it. Perhaps try modifying the project so that instead of providing access to Items it provides access to Employees instead.</p>



<p>If you run into any problems, or have questions, please feel free to email me (timdietrich@me.com). Another great resource for your general Xojo questions is the Xojo Programming <a href="https://forum.xojo.com">Forum</a>.</p>



<p>Have fun!</p>



<h3 class="wp-block-heading">Questions &amp; Answers</h3>



<h4 class="wp-block-heading">Do you prefer to use RESTlets instead of SuiteTalk REST? If so, why?</h4>



<p>Yes, I much prefer using RESTlets in all of my NetSuite integration projects. With RESTlets I have more control over the functionality that the API provides, and more control over how the responses are formatted. Also, my experience has been that RESTlets are slightly faster than SuiteTalk REST.</p>



<p>That being said, SuiteTalk REST does have some advantages over RESTlets. For example, SuiteTalk REST provides endpoints that you can use to get metadata, which is something that is often difficult to do with a RESTlet. But perhaps the biggest advantage of SuiteTalk REST is that, unlike RESTlets, there is nothing extra that needs to be installed in your NetSuite account. It&#8217;s simply a matter of enabling it.</p>



<h4 class="wp-block-heading">You mentioned some NetSuite customer statistics in your presentation. Can you repeat those?</h4>



<p>Sure. During his SuiteWorld keynote presentation this year, Gary Wiessinger (SVP of NetSuite Application Development) mentioned NetSuite&#8217;s growth in terms of the number of customers that are using NetSuite. So as of October 2023, 37,000 customers are using NetSuite, and that represents 324,000 organizations. And those customers are located in 219 countries and territories.</p>



<h4 class="wp-block-heading">As a Xojo developer, how can I get started with NetSuite?</h4>



<p>You should first try to get access to a NetSuite account that you can experiment with. Unfortunately, that&#8217;s not as easy as it is with other platforms (such as Salesforce or ServiceNow), where they provide developers with test accounts. My advice would be to reach out to a local NetSuite partner, and see if you can build a relationship with them, and try to get their help in getting started.</p>



<h4 class="wp-block-heading">After the demo, you mentioned another Xojo project that extends the Android functionality. What was that?</h4>



<p>It&#8217;s called Android Design Extensions, and there&#8217;s a great blog post about it <a href="https://blog.xojo.com/2023/12/12/android-design-extensions-2-0-for-xojo-2023r3-and-later/" data-type="link" data-id="https://blog.xojo.com/2023/12/12/android-design-extensions-2-0-for-xojo-2023r3-and-later/">here</a>. Read multiple posts about <a href="https://blog.xojo.com/tag/android-design-extensions/">Android Design Extensions</a> on the Xojo Blog.</p>



<h3 class="wp-block-heading">Wrapping Up</h3>



<p>Thanks again for your interest in Xojo and in using it to develop apps that integrate with NetSuite. I hope you&#8217;ve found the webinar and the Xojo project to be helpful.</p>



<p>Happy holidays!</p>



<p><em>Tim Dietrich develops custom software for businesses that are running on NetSuite. He makes extensive use of Xojo to develop mobile, desktop, Web apps, and more &#8211; all of which integrate seamlessly with NetSuite. To learn more, visit: https://timdietrich.me</em></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Testing REST-based Web Services</title>
		<link>https://blog.xojo.com/2023/03/07/testing-rest-based-web-services/</link>
		
		<dc:creator><![CDATA[Geoff Perlman]]></dc:creator>
		<pubDate>Tue, 07 Mar 2023 15:16:55 +0000</pubDate>
				<category><![CDATA[Learning]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Beginner Tips]]></category>
		<category><![CDATA[Rapid Application Development]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[URLConnection]]></category>
		<category><![CDATA[Web Service]]></category>
		<category><![CDATA[webdev]]></category>
		<category><![CDATA[Xojo Programming Language]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=11358</guid>

					<description><![CDATA[Using Xojo's URLConnection to communicate with web services is pretty straightforward. But testing the actual REST API calls can get tricky. To make it easier to test and experiment with REST API calls, Paul created a app in Xojo that lets you test REST APIs. He called it RESTy in its original format back in 2015. You can download the updated project here built with Xojo 2022r4.1.]]></description>
										<content:encoded><![CDATA[
<p>Using Xojo&#8217;s URLConnection to communicate with web services is pretty straightforward. But testing the actual REST API calls can get tricky. To make it easier to test and experiment with REST API calls, Paul created an app in Xojo for doing just this. He called it RESTy in its original format back in 2015. The most recent version of the example project can be found in Xojo by choosing File > New Project, clicking on Examples then clicking on Communication > Internet > Web Services >RESTy.</p>



<span id="more-11358"></span>



<p>RESTy uses the <a href="https://documentation.xojo.com/api/networking/urlconnection.html#urlconnection">URLConnection</a> class to send a request to a web service and get a result. If the result is text (JSON, for example)&nbsp;it displays in the <strong>Response</strong> tab. Here, I am calling the <a href="https://documentation.xojo.com/topics/communication/internet/testing_a_web_service.html">Eddie&#8217;s Electronics web service</a> to return a list of all the customers by specifying the URL and clicking the Fetch button:</p>



<figure class="wp-block-image size-large"><img decoding="async" width="965" height="1024" src="https://blog.xojo.com/wp-content/uploads/2023/03/getallcustomers-965x1024.png" alt="" class="wp-image-11365" srcset="https://blog.xojo.com/wp-content/uploads/2023/03/getallcustomers-965x1024.png 965w, https://blog.xojo.com/wp-content/uploads/2023/03/getallcustomers-283x300.png 283w, https://blog.xojo.com/wp-content/uploads/2023/03/getallcustomers-768x815.png 768w, https://blog.xojo.com/wp-content/uploads/2023/03/getallcustomers.png 1200w" sizes="(max-width: 965px) 100vw, 965px" /></figure>



<p>For other data (binary data such as pictures) you can use the Fetch to File button to save the request to a file.</p>



<p>The Authentication tab is used to provide Basic Authentication should the web service require it.</p>



<p>The Request Content tab can be used to provide Content data that the request might need. For example, the Eddie&#8217;s Electronics web service also lets you request the details for a specific customer by providing simple JSON containing the customer ID. To try this using RESTy app:</p>



<ol class="wp-block-list">
<li>Click on the Request Content Tab.</li>



<li>To indicate the customer you wish to retrieve, enter the following JSON into the field on that tab: <code>{"ID": 10039}</code></li>



<li>Select <strong>POST</strong> from the Send Method popup menu.</li>



<li>In the URL field, enter: <code>https://eews-demos.xojo.com/GetCustomer</code></li>



<li>Press the Fetch button.</li>
</ol>



<p>If you have entered everything correctly, will see the data for Caleb Horn in JSON format:</p>



<figure class="wp-block-image size-large"><img decoding="async" width="965" height="1024" src="https://blog.xojo.com/wp-content/uploads/2023/03/getonecustomer-1-965x1024.png" alt="" class="wp-image-11367" srcset="https://blog.xojo.com/wp-content/uploads/2023/03/getonecustomer-1-965x1024.png 965w, https://blog.xojo.com/wp-content/uploads/2023/03/getonecustomer-1-283x300.png 283w, https://blog.xojo.com/wp-content/uploads/2023/03/getonecustomer-1-768x815.png 768w, https://blog.xojo.com/wp-content/uploads/2023/03/getonecustomer-1.png 1200w" sizes="(max-width: 965px) 100vw, 965px" /></figure>



<p>And to see the JSON formatted nicely, click the Format JSON button:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="965" height="1024" src="https://blog.xojo.com/wp-content/uploads/2023/03/formattedJSON-965x1024.png" alt="" class="wp-image-11368" srcset="https://blog.xojo.com/wp-content/uploads/2023/03/formattedJSON-965x1024.png 965w, https://blog.xojo.com/wp-content/uploads/2023/03/formattedJSON-283x300.png 283w, https://blog.xojo.com/wp-content/uploads/2023/03/formattedJSON-768x815.png 768w, https://blog.xojo.com/wp-content/uploads/2023/03/formattedJSON.png 1200w" sizes="auto, (max-width: 965px) 100vw, 965px" /></figure>



<p>This will let you you explore calling various REST API services. You can explore the source code to see how it uses URLConnection to do so.</p>



<p>To be sure, RESTy is very basic, but you have the source code so you and add features to it and modify it for your own testing needs.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Web Services: Xojo Web, at your service</title>
		<link>https://blog.xojo.com/2018/09/26/web-services-xojo-web-at-your-service/</link>
		
		<dc:creator><![CDATA[Javier Menendez]]></dc:creator>
		<pubDate>Wed, 26 Sep 2018 10:00:59 +0000</pubDate>
				<category><![CDATA[Learning]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Middleware]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[Web Service]]></category>
		<category><![CDATA[webdev]]></category>
		<category><![CDATA[Xojo Programming Language]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=4950</guid>

					<description><![CDATA[In this two part tutorial we will see how easy it is to create a basic web service using Xojo Web. In the second part, we will create a Desktop client to talk with the web service (you may want to add iOS to the list).]]></description>
										<content:encoded><![CDATA[<p>Using Xojo Web to create complete web apps and solutions means not having to learn a bunch of interpreted languages and dozens of ever-changing frameworks. I&#8217;m looking at you: HTML, CSS (is that even a language?), JavaScript, PHP, et al. Of course, <a href="http://xojo.com/products/web.php">Xojo Web</a> not only makes it possible to create your own web apps, but it also acts as the perfect middleware that your desktop and iOS apps can communicate with. Learn about <strong>APIs</strong> and web services with Xojo in the tutorial blog post.<span id="more-4950"></span></p>
<p>In this two part tutorial you will see how easy it is to create a basic web service using Xojo Web. In the second part, we will create a Desktop client to talk with the web service (you may want to add iOS to the list).</p>
<p>Before we start, let me point out that this tutorial leaves out some details related to error checking, validation, data sanitizing and other specifics related to inputs and outputs in order to focus on the central topic. In addition, if you want to follow and reproduce the steps of this tutorial, then you need to download the <a href="https://github.com/lerocha/chinook-database/raw/master/ChinookDatabase/DataSources/Chinook_Sqlite.sqlite">Chinook Database, </a>named &#8220;test.sqlite&#8221; in this tutorial.</p>
<h2>Services in practice</h2>
<p>Let&#8217;s start creating a web service! Open the Xojo IDE, create a new <b>Web project</b>, and name it <code>WebService</code>. The first thing you&#8217;ll notice is that Xojo adds a web page to the project by default &#8211; even when our web service does not display a UI. The good part is that you can mix both worlds, adding the webservice part to your regular Web app!.</p>
<p>In fact this tutorial will put all the logic in the App object. Start by adding a new <b>property</b> in charge of the reference to our <b>SQLite</b> database (of course, it will work also with <b>PostgreSQL</b> or <b>MySQL</b> engines). Select the <code>App</code> object from the <b>Navigator</b> (the left panel in the Xojo IDE), choosing the <code>Insert &gt; Property</code> option from the contextual menu. With the new property selected, go to the <b>Inspector</b> to set the name, type and scope using these values:</p>
<ul>
<li><b>Name: </b>Database</li>
<li><b>Type: </b>SQLiteDatabase</li>
<li><b>Scope: </b>Private</li>
</ul>
<p>Next, we will add the Chinook Database to the Resources folder of our Web App. For that, select the deployment target under Build Settings (it can be macOS, Windows, Linux or Xojo Cloud, for example), and add a Copy Files build step to it. In the resulting Editor, add the Chinook database SQLite file and make sure you select the &#8220;Resources Folder&#8221; entry in the Destination popup menu, and the &#8220;Both&#8221; entry in the Applies To popup menu.</p>
<p>Now is time to create a new SQLiteDatabase instance and assign it to this property, so it will point to the SQLite database file when the app is running. For that, make sure the <code>App</code> object is selected and add the <code>Opening</code> <b>Event Handler</b> to it using the <code>Insert &gt; Event</code> option. Write the following code in the resulting <b>Code Editor</b>:</p>
<pre>#Pragma Unused args

Var f As FolderItem = SpecialFolder.Resource("Chinook_Sqlite.sqlite")

If f.Exists Then
  
  Try
    database = New SQLiteDatabase
    database.DatabaseFile = f
    
    Call database.Connect
  Catch e As DatabaseException
    MessageBox "Error connecting to the database"
  End Try
  
End If</pre>
<p>As you can see, it is pretty much the same code we already use when creating <b>SQLiteDatabase</b> instances in our Desktop apps, <em>linking</em> to our SQLite database file and stablishing the connection so we can operate with the database engine from our app.</p>
<h2>All the Magic of HandleURL</h2>
<p>Xojo Web projects offer a simple way to handle the request received. It is using the <code>HandleURL</code> event. This is the one that fires every time a client app (it may be a Web Browser, desktop or mobile app) connects to the URL associated with the <b>IP address and port combination</b> that is <em>listening</em> for incoming requests.</p>
<p>For example, a valid URL that can be <b>trapped</b> and processed by <code>HandleURL</code> is:</p>
<pre>http://www.nice-web-domain.com/getCustomers</pre>
<p>Where <code>getCustomers</code> is in this case one of our API methods.</p>
<p>So, with the <code>App</code> object selectd, choose <code>Insert &gt; Event</code> in order to add the <code>HandleURL</code> event.</p>
<p>As we will see, once the event has been added to a web app, it will receive the <code>Request</code> parameter (a <code>WebRequest</code> data type), waiting from us to send back a <code>Boolean</code> value as response: <code>True</code> to process the request or <code>False</code> (the default value) to ignore the response.</p>
<h2>Introducing Request, where the information lives!</h2>
<p>In fact, we will find in the <code>Request</code> object everything we need to process and (if it is the case) respond to the request from our Web service. For example, through we can get the interesting component from the <code>Path</code> property. If we consider this URL:</p>
<p><code>http://www.nice-web-domain.com/getCustomers?spain</code></p>
<p>The <code>Request.Path</code> property will return the <code>getCustomers</code> string; so our web service can process it acordingly from this point on.</p>
<h2>Receiving and Sending JSON data</h2>
<p>In order to keep this tutorial brief, our web API only has two methods in it: <code>GetAll</code> and <code>AddAlbum</code>. Using the first one, the client app will get the album name in the database wrapped in JSON format. With the second method, our client app will ask the web service to add a new record (a new album) to the right table on our example database.</p>
<p>How can we process the request associated data inside the <code>HandleURL</code> event? Here is where we will find very useful another of the <code>Request</code> object properties. The <code>Body</code> property includes the sent data as part of the request that are not already present in the headers. Generally speaking, it includes additional data via the <b>PUT</b> and <b>POST</b> verbs.</p>
<p>Now we can put the following code into our <code>HandleURL</code> Event Handler:</p>
<pre>Select Case Request.Path // What is the method received as part of the request? (URL)
Case "GetAll"
  Var output As JSONItem = GetAllAlbums // Assign the processed data to the output variable, if the received method is 'GetAllAlbums'
  
  Response.Header("charset") = "utf-8"
  Response.MIMEType = "application/json"
  Response.Status = 200
  response.write( output.ToString ) // And send it back to the client that made the request, converting the JSON to a String in first place
  
Case "AddAlbum"
  Var data As String = Request.Body.DefineEncoding(encodings.UTF8) // We have to apply the right encoding to the received data
  Var Input As JSONItem = New JSONItem( data ) // Creating a new JSON object from it
  addNewAlbum( Input.Value("newAlbum") ) // In this case, the request is to add a new Album to the database; passing thus the received data as part of the input
End Select

Return True</pre>
<p>The main point here is that we assign the received data to the <code>data</code> variable (if any), and define a known encoding to them so we won&#8217;t get into trouble while processing them afterwards. Of course, our example always expects to receive the additional data in JSON format, so this is why we create a new JSON instance from this data.</p>
<p>We use the <code>Select…Case</code> command to decide what method has to execute the web service, and that is based on the component stored in the <code>Path</code> property as you recall. So, if the request uses the <code>GetAll</code> method in the URL, we will call the real method <code>GetAllAlbums</code> in our Xojo code. After processing the information it will return a new <code>JSONItem</code> as the response we will send to the client.</p>
<p>How can we send the response to the request? Really simple: calling the <code>Write</code> method on the Response object, passing as parameter the text we want to send back. In our example, this is the <code>JSONItem</code> referenced by the <code>Output</code> variable. We also use the Response object to set the character encoding to UTF-8 and the MIME type to &#8220;Application/json&#8221;, in addition of setting the status value to 200 (that is, the request has been successfully handled).</p>
<p>If we receive a request with the <code>AddAlbum</code> method of our API, then we call the real <code>addNewAlbum</code> method in our Xojo code, passing as parameter the <code>JSONItem</code> object in charge of store the received data from the request (this is the one referenced by the <code>input</code> variable). In fact, the record structure is stored inside the <code>newAlbum</code> root node of the JSONItem.</p>
<h2>When it comes to the Database</h2>
<p>While <code>HandleURL</code> is in charge of processing the received request, we will use a couple of methods in our example app that will act as a <em>link</em> between the API and the database in the backend, both for retrieving and storing the requested information. (In a real world app it is very advisable to introduce checks and data sanitization before dealing with the database!)</p>
<p>Choose the <code>App</code> object again and use the <code>Insert &gt; Method</code> option in order to add the <code>GetAllAlbums</code> method, using the following method signature for that:</p>
<ul>
<li style="list-style-type: none;">
<ul>
<li><b>Method Name: </b>getAllAlbums</li>
<li><b>Return Type: </b>JSONItem</li>
<li><b>Scope: </b>Private</li>
</ul>
</li>
</ul>
<p>This is the code in charge of generating the JSONitem that we will <em>write </em>as part of the request response, including the <b>node</b> for every expected database record from the <code>Album</code> table in our example database:</p>
<pre>Var rc As RowSet = database.SelectSQL("Select * from album order by title asc") // Get the Recordset as result of the SQL selection: all the records
Var item As New JSONItem

If rc.RowCount &gt; 0 Then // We have records on the RecordSet
  
  While Not rc.AfterLastRow // so lets iterate them!
    Var d As New Dictionary // creating a new dictionary for each record, and that we will convert in a node
    d.Value("artistid") = rc.Column("artistid").StringValue // assingning the record ID to the name 'ArtistId' of the JSONItem
    d.Value("title") = rc.Column("title").StringValue // and the Title value to the 'Title' field of the JSONItem
    item.Value(rc.Column("albumid").StringValue) = d // You know you can assign a Dictionary as the value for a JSONItem node. Very useful!
    
    rc.MoveToNextRow
  Wend
  
  rc.Close
  
End If

var output As New JSONItem

output.Value("AllAlbums") = item // Then let's hang all these records form a main Node

Return output // And return it to the caller</pre>
<p>Next, create a new method named <code>addNewAlbum</code>. This is the one our web service will use to add a new record to the database, using for that the received data as part of the request. Use the following signature for the method definition:</p>
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li><b>Method Name: </b>addNewAlbum</li>
<li><b>Paramters: </b>item as JSONItem</li>
<li><b>Scope:</b> Private</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>And put the following code in the associated Code Editor:</p>
<pre>Var title As String = item.Value("Title") // get the data associated to the "Title" field
Var artistid As String = item.Value("ArtistId") // and the 'ArtistID'

database.ExecuteSQL("insert into album(title,artistid) values(?, ?)", title, artistid ) // and insert that data as a new record into the database table
</pre>
<p>As you can see, the code is very simple: it gets the values for the received keys in the JSONitem nodes and uses them as part of the SQL sentence in order to add a new record to the database.</p>
<h1>A Web service… ready to serve!</h1>
<p>As you have seen, the code and app structure are really minimal! Of course, this is just a simple example but it gives you a good idea of the kind of possibilities web services offer and how fast you can put it together using Xojo and <strong>OOP</strong> concepts you already know! Of course, you can run your web app (and services) right from the IDE (just make sure to select 8081 as the Debug Port)… what is probably the recommended way to follow this simple example. For other more complex web apps, remember that you can use the one click solution <a href="https://www.xojo.com/cloud/"><strong>Xojo Cloud</strong></a> and of course any compatible Linux, Windows or Mac server.</p>
<p><em>Javier Rodri­guez has been the Xojo Spanish Evangelist since 2008, he’s also a Developer, Consultant and Trainer who has be using Xojo since 1998. He manages <a href="http://www.aprendexojo.com">AprendeXojo.com</a> and is the developer behind the GuancheMOS plug-in for Xojo Developers, Markdown Parser for Xojo, HTMLColorizer for Xojo and the Snippery app, among others</em></p>
<p>*<a href="https://www.aprendexojo.com/2016/06/crear-servicio-web-con-xojo/">Read this post in Spanish</a></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Identify Images Using IBM Watson&#8217;s Remote APIs</title>
		<link>https://blog.xojo.com/2018/05/23/identify-images-using-ibm-watsons-remote-apis/</link>
		
		<dc:creator><![CDATA[Xojo]]></dc:creator>
		<pubDate>Wed, 23 May 2018 10:00:33 +0000</pubDate>
				<category><![CDATA[Fun]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[AI]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[IBM]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[Watson]]></category>
		<category><![CDATA[Xojo Framework]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=4293</guid>

					<description><![CDATA[Have some fun with Artificial Intelligence and Xojo! See examples from IBM's Watson services and how to use them with Xojo to classify images.]]></description>
										<content:encoded><![CDATA[<p>Some of the most interesting web services you can use with Xojo through remote API calls are related to <a href="https://en.wikipedia.org/wiki/Artificial_intelligence">Artificial Intelligence</a>. There are many different APIs provided by the main players in the AI sector, but IBM&#8217;s Watson is by far the most well known.</p>
<p>I&#8217;m going to show you how to connect to IBM&#8217;s Watson services with REST APIs and how to use them with Xojo projects to identify images. This is just one example, of course, of the many ways to utilize Watson and AI in your Xojo apps.</p>
<p><span id="more-4293"></span></p>
<h3>IBM Watson</h3>
<p><a href="https://www.ibm.com/watson/" target="_blank" rel="noopener">IBM&#8217;s Watson services</a> have been online for several years and are continuously updated. They are paid services but you can create a Lite user to test and evaluate them. The <a href="https://console.bluemix.net/developer/watson/documentation?cm_mc_uid=39948455095014385868305&amp;cm_mc_sid_50200000=73496051523601646255&amp;cm_mc_sid_52640000=69577461523601646258" target="_blank" rel="noopener">documentation and variety</a> of services are huge and includes (among other things) image identification services.</p>
<h4>Identify images with Watson</h4>
<p>This service mainly offers two possibilities: identifying the faces in an image (returning the position, the probable gender of the subject and the probable age range) and the classification (i.e. the recognition of possible tags that can be associated with the image).</p>
<div class="keyconcept"><strong>The key concept of this type of process is: Probability</strong><br />
The result is a probability, not a certainty. It&#8217;s up to your app to accept or reject the result and how to use it. For example, you can set a threshold and automatically accept the results and send the user the uncertain result to confirm or refuse.</div>
<p>Watson&#8217;s <a href="https://www.ibm.com/developerworks/community/blogs/5things/entry/5_things_to_know_about_Watson_Natural_Language_Classifier?lang=en">Natural Language Classifier</a>, is a service that &#8220;applies cognitive computing techniques to return best matching predefined classes for short text inputs, such as a sentence or phrase&#8221;. It is really large (and the definitions are localized in many languages); moreover you can create your own classifiers specific to projects. The Lite user can create only one classifier at a time that is replaceable but not updatable. Another limit is the number and total size of the images that you can use to address your classifier.</p>
<p>Watson&#8217;s documentation is complete and easy to use. After creating the service in your account, you can start using them with the terminal or through the web page relative to the selected service.</p>
<h3>How to use Watson with Xojo</h3>
<p>The services use a REST API so you&#8217;ll use <a href="http://developer.xojo.com/xojo-net-httpsocket">Xojo.Net.HTTPSocket</a> as the base class to create the object that will consume these services. To learn more about using Xojo with a REST API, you should read up on that before continuing: <a href="https://blog.xojo.com/2015/10/01/cats-up-using-httpsocket-with-the-cat-rest-api/" target="_blank" rel="noopener">Cats Up: Using the HTTPSocket with the Cat REST API,</a> <a href="https://blog.xojo.com/2018/02/06/pdf-file-generation-there-is-an-api-for-that/" target="_blank" rel="noopener">PDF File Generation? There is an API for that</a> and <a href="https://www.youtube.com/playlist?list=PLPoq910Q9jXiH5A32myqHwd1WLuUnBTuO">Web Services Video Playlist</a>.</p>
<p>In this example, the base class is called &#8220;WatsonAPI&#8221;. This class will deal with the communication with the API (sending and initial interpretation of the answer) and will have some common features (such as zipping several images so they can be sent all at once). Moreover, since the interaction with the service is asynchronous, the class will have to manage the serialization of the different requests and take care to return the result to the correct call.</p>
<p>Next, you&#8217;ll define a delegate who will have as an argument the answer (positive, negative or error) that will have as its signature a <a href="http://developer.xojo.com/xojo-core-dictionary">Xojo.Core.Dictionary</a>:</p>
<pre>WatsonReplyFunction(reply as Xojo.Core.Dictionary)</pre>
<p>Now you&#8217;ll define two private properties: id and callback. You&#8217;ll use id to distinguish the various call, and callback will be the function to call when there&#8217;s a the result.</p>
<pre>Private Property id as Text
Private Property callback as WatsonReplyFunction</pre>
<p>The constructor (protected because the subclasses will call it) can be of this kind:</p>
<pre>Protected Sub Constructor( cb as WatsonAPI.WatsonReplyFunction)
  // Register the callback
  callback=cb
  Super.Constructor
  register Me
End Sub</pre>
<p><em>Register</em> is a private shared function that assigns the identifier to the object and saves the pair id, object in a shared dictionary. There&#8217;s also a <em>deRegister </em>function that will delete the object whose identifier is passed.</p>
<p>As noted before, you&#8217;ll use a dictionary to represent the API result because it&#8217;s the format used for positive or negative API replies. Moreover, we can use the same format for network error replies. The dictionary will contain at least 3 values: <em>success</em> as boolean for a positive or negative reply, <em>status</em> as integer for the reply http status and <em>result</em> as text or dictionary to represent the current reply. Since it&#8217;s a dictionary, we can easly add more information as needed. Subclasses or consumer classes can transform this data structure in a more specific way (class, record or whatever).</p>
<p>Now you will implement the major events:</p>
<pre>Sub Error(err as RuntimeException) Handles Error
  //All replies will have the same structure
  //In the event of an error, the returned dictionary must be structured as correct one
  Dim d As New Xojo.Core.Dictionary
  d.Value("success")=False
  d.Value("status")=0
  d.Value("result")=err.Reason
  //Delete the object from the dictionary
  deRegister(Me)
  //return the reply
  callback.Invoke(d)
End Sub


Sub PageReceived(URL as Text, HTTPStatus as Integer, Content as Xojo.Core.MemoryBlock&gt;) Handles PageReceived
  #Pragma Unused url

  //evaluate the reply
  Dim d As Xojo.Core.Dictionary
  Dim t As Text
  Try
    t=Xojo.Core.TextEncoding.UTF8.ConvertDataToText(Content)
  Catch
    t=""
  End Try
  If Not t.Empty Then
    Try
      d=Xojo.Data.ParseJSON(t)
    Catch
      d=Nil
    End Try
  End If
  Dim reply As New Xojo.Core.Dictionary
  reply.Value("success")=HTTPStatus=200 And d&lt;&gt;Nil
  reply.Value("status")=HTTPStatus
  If d=Nil Then
    reply.Value("result")=t
  Else
    reply.Value("result")=d
  End If
  //Delete the object from the dictionary
  deRegister(Me)
  //return the reply
  callback.Invoke(reply)
End Sub</pre>
<p>Now you can create a subclass to classify the images: WatsonVisualRecognition as subclass of WastonAPI.</p>
<p>For the image classification you can use one or more of the classifiers and/or the default one or even those in beta (currently Food and Explicit). So let&#8217;s define the constants related to these classifiers:</p>
<pre>Public Const IBMDefault as Text =default
Public Const IBMExplicit as Text = explicit
Public Const IBMFood As Text = food</pre>
<p>&#8230; and the ones related to the services:</p>
<pre>//The current version of the service
Private Const version As Text = 2016-05-20

//The address actually depends on the user settings
Private Const kBaseUrl As Text = https://gateway.watsonplatform.net/visual-recognition/api/v3/

//The key to use the service
Private Const keyVision As Text = •••••••</pre>
<p>You can now define a public shared method for analyzing an image on the web:</p>
<pre>Public Shared Sub classifyImage(cb As WastonAPI.WatsonReplyFunction, imageUrl As Text, threshold As Single=0.5, paramArray classifiers As Text)
  //The method requires a method to be called to return the results,
  // the address of the image to be analyzed
  // the minimum value to be considered for recognition
  // a list of classifiers to use

  //Let's create the instance linking it to the callback
  Dim w As New WatsonVisualRecognition(cb)

  //threshold is the minimum acceptable value for classification
  //  must be between 0 and 1
  If threshold&lt;0.0 Then threshold=0.0
  If threshold&gt;1.0 Then threshold=1.0

  //For classifiers I can use both the ones provided and mine
  //none means the default one
  Dim useIBM As Boolean
  Dim usePersonal As Boolean
  Dim usedClassifiers() As Text
  For i As Integer=0 To classifiers.Ubound
    Select Case classifiers(i)
    Case IBMDefault
      useIBM=True
    Case IBMExplicit, IBMFood
      useIBM=True
      //These classifiers are in English only 
      w.RequestHeader("Accept-Language")="en"
    Else
      usePersonal=True
    End Select
    If usedClassifiers.IndexOf(classifiers(i))=-11 Then usedClassifiers.Append  classifiers(i)
  Next
  Dim classifierIds As Text=Text.Join(usedClassifiers, ",")

  //Set the kind of the classifiers used
  Dim usedOwners() As Text
  If useIBM Then usedOwners.Append "IBM"
  If usePersonal Then usedOwners.Append "me"
  Dim owners As Text=Text.Join(usedOwners, ",")

  //Create the URL to be called
  Dim url As Text=kBaseUrl+"classify"

  //I create the list of arguments
  Dim args() As Text
  args.Append "api_key="+keyVision
  args.Append "version="+version
  args.Append "url="+imageUrl
  If Not owners.Empty Then args.Append "owners="+owners
  If Not classifierIds.Empty Then args.Append "classifier_ids="+classifierIds
  If threshold&gt;0 Then args.Append "threshold="+threshold.ToText
  Dim parameters As Text=Text.&gt;Join(args, "&amp;")

  w.Send "GET", url+If(parameters.Empty, "", "?"+parameters)
End Sub</pre>
<p>Finally, you can request the classification of an image. For example, put a button in a Window and in the Action event put the following code:</p>
<pre>WatsonVisualRecognition.classifyImage(WeakAddressOf analyzeResponse, "https://watson-developer-cloud.github.io/doc-tutorial-downloads/visual-recognition/fruitbowl.jpg", .3)</pre>
<p>Where <em>analyzeResponse</em> is the method that will read the results translating the Dictionary into something useful like actions for a database, a textual list or a simple text message.</p>
<p>Starting from this simple method, it is possible to create all the others, adding a bit of utility functions to the WatsonAPI base class.</p>
<p>As an example, it is possible to obtain the basic information about the people in this image and display it as an overlay:</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-4295" src="https://blog.xojo.com/wp-content/uploads/2018/05/faces.png" alt="" width="1433" height="953" /></p>
<p>Or update a database of images with classifications to then find the images of a specific type:</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-4296" src="https://blog.xojo.com/wp-content/uploads/2018/05/food.png" alt="" width="2446" height="1054" /></p>
<h3><img />Create your own classifiers</h3>
<p>Starting from this object it is easy to create an application to generate, update, and verify a classifier that is specific to this solution. While you can do it with the provided web interface, you can create a Xojo app that can return the feedback in a much easier and manageable way; and you can add some methods to automate the process of automatically discarding bad images and adding new ones in order to refine your classifier better.</p>
<h3>Conclusions</h3>
<p>Watson&#8217;s API services allow you to add a bit of artificial intelligence to your Xojo projects. The simplicity of the classes required to do this are clear proof of Xojo&#8217;s versatility.</p>
<p>It&#8217;s important to keep in mind that this service is not instantaneous. This is due in large part to network traffic; generally for sending the data and receiving the answer.</p>
<p>A really interesting option if you develop for MacOS would be to download your classifier in CoreML format and use it offline with <a href="https://www.mbsplugins.eu/CoreMLOpenModel.shtml">MBS Core ML plugin</a>.</p>
<p><em>Antonio Rinaldi is a professional engineer, Xojo developer for almost twenty years, Xojo evangelist for Italy since 2014, consultant and teacher. He develops extensions for Xojo iOS that you can find in the Xojo Store, and manages <a href="http://www.xojoitaliablog.com">XojoItaliaBlog.com</a>. Musician, composer, lover of good food, traveler and constantly curious, he is always looking for new ideas to expand his knowledge.</em></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Making An iOS App For The Daily WTF API</title>
		<link>https://blog.xojo.com/2016/01/20/making-an-ios-app-for-the-daily-wtf-api/</link>
		
		<dc:creator><![CDATA[Paul Lefebvre]]></dc:creator>
		<pubDate>Wed, 20 Jan 2016 00:00:00 +0000</pubDate>
				<category><![CDATA[iOS]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Cats]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[PAW]]></category>
		<category><![CDATA[REST]]></category>
		<guid isPermaLink="false">http://blogtemp.xojo.com/2016/01/20/making-an-ios-app-for-the-daily-wtf-api/</guid>

					<description><![CDATA[Use web services to display articles from The Daily WTF technology snafu web site.]]></description>
										<content:encoded><![CDATA[<p>If you work in the technologiy industry, I&#8217;m sure you&#8217;ve heard of the <a href="http://thedailywtf.com">Daily WTF</a> site. Their fun stories about technology gone wrong makes it one of my favorite web sites.</p>
<p><span id="more-233"></span></p>
<p>Recently they just <a href="http://thedailywtf.com/articles/tdwtf-api">announced a web services API</a> for accessing their articles and other information. And as I&#8217;ve talked about <a href="../../../com/xojo/blog/test-web-services-with-rest-tester.html" target="_blank" rel="noopener">in</a> <a href="../../../com/xojo/blog/format-sql.html" target="_blank" rel="noopener">other</a> <a href="../../../com/xojo/blog/how-to-write-a-slackbot-in-less-than-20-lines-of-code.html" target="_blank" rel="noopener">posts</a> and <a href="https://www.youtube.com/playlist?list=PLPoq910Q9jXiH5A32myqHwd1WLuUnBTuO" target="_blank" rel="noopener">webinars</a>, it&#8217;s often quite easy to use web services with Xojo apps.</p>
<p>I&#8217;ll show you how you can quickly create an iOS app that shows the most recent TDWTF posts and then displays them when you tap on their title.</p>
<p>To start, create a Xojo iOS project.</p>
<p>On the default View (View1), use the Inspector to set a couple properties:</p>
<ul>
<li>BackButtonTitle: Articles</li>
<li>Title: The Daily WTF</li>
</ul>
<p>Now drag a <a href="http://developer.xojo.com/iostable">Table</a> from the Library onto the View and stretch it to fit the entire layout area. Name the table <strong>ArticleTable</strong>. This Table will be used to display the list of recent articles.</p>
<p>To get the articles, you just have to make the appropriate API call. Looking at the <a href="https://github.com/tdwtf/WtfWebApp/blob/master/Docs/API.md">API docs</a>, there is an API command called /articles/recent which returns a JSON document of the recent articles and related information. This is the actual API call. To see its JSON results, use a tool like <a href="https://luckymarmot.com/paw">Paw</a> (now with <a href="../../../com/xojo/blog/generating-xojo-code-from-paw.html">Xojo extensions</a>) or <a href="../../../com/xojo/blog/test-web-services-with-rest-tester.html">RESTy</a> with this URL (a browser will also show the unformatted JSON):</p>
<p><a href="http://thedailywtf.com/api/articles/recent">http://thedailywtf.com/api/articles/recent</a></p>
<p>If you look at the JSON results, you&#8217;ll see that it returns an array of articles with a &#8220;Title&#8221; entry containing the title of the article and a &#8220;Url&#8221; entry containing the URL of the article.</p>
<p>To call this in the Xojo app, I&#8217;ll use an <a href="http://developer.xojo.com/xojo-net-httpsocket">HTTPSocket</a>. In the Library, drag the item called &#8220;Generic Object&#8221; onto the Layout. It will appear in the Shelf at the bottom. In its Inspector, change the name to <strong>WTFSocket</strong> and set its super to &#8220;Xojo.Net.HTTPSocket&#8221;.</p>
<p>Now add an event handler to the socket, right-&gt;click on the socket, select &#8220;Add To&#8221; and then &#8220;Event Handler&#8221;. Add the PageReceived event handler. In it, put this code to request the articles:</p>
<pre>// Convert the binary Content data to JSON text and then
// parse it to an array.
Dim jsonText As Text = TextEncoding.UTF8.ConvertDataToText(Content)
Dim jsonArray() As Auto = Data.ParseJSON(jsonText)

// Loop through the array and add each article to
// the table.
ArticleTable.AddSection("")
For i As Integer = 0 To jsonArray.Ubound
  Dim article As Dictionary = jsonArray(i)

  Dim cell As iOSTableCellData = ArticleTable.CreateCell
  cell.Text = article.Value("Title")
  cell.Tag = article.Value("Url")

  Dim author As Dictionary = article.Value("Author")
  cell.DetailText = article.Value("DisplayDate") + " by " + author.Value("Name")
  ArticleTable.AddRow(0, cell)
Next</pre>
<p>The URL is being put into the Tag for the cell so that it can be used later to display the article when its row is tapped.</p>
<p>You&#8217;ll also see I&#8217;m also accessing the &#8220;DisplayDate&#8221; value and grabbing the &#8220;Name&#8221; from the &#8220;Author&#8221; object in the JSON.</p>
<p>Now you&#8217;ll want to call the web service. Add the Open event handler to the View with this code:</p>
<pre>// Call the /articles/recent web service
WTFSocket.Send("GET", "http://thedailywtf.com/api/articles/recent")</pre>
<p>Run the project and you&#8217;ll see the list of recent article appear:</p>
<p><img loading="lazy" decoding="async" class="aligncenter" title="WTFArticleList.png" src="https://blog.xojo.com/wp-content/uploads/2016/01/WTFArticleList.pngt1466486449161ampwidth480ampheight742" sizes="auto, (max-width: 480px) 100vw, 480px" alt="WTFArticleList.png" width="480" height="742" /></p>
<p>The final step is to display the article when it is tapped in the list. You&#8217;ll want another View to display the article (Insert-&gt;View). Name the view <strong>ArticleView</strong>. On this View, set the NavigationBarVisible property to ON and drag an HTML Viewer onto it. Make the HTML Viewer fill the entire View layout and name it <strong>ArticleViewer</strong>.</p>
<p>Add a method to ArticleView called <strong>ShowArticle(url As Text)</strong> with this code:</p>
<pre>ArticleViewer.LoadURL(url)</pre>
<p>This method loads the URL into the HTML Viewer and is called when its row is tapped in the list of articles.</p>
<p>Speaking of which, back on View1 add the Action event handler to the table with this code:</p>
<pre>// Get the URL from the tag for the tapped row
Dim url As Text = Me.RowData(section, row).Tag

// Display the article on the new view and show it
Dim v As New ArticleView
v.ShowArticle(url)
PushTo(v)</pre>
<p>Now run the project. You&#8217;ll see the list of article as before. Tap on an article to show the new view with the article.</p>
<p><img loading="lazy" decoding="async" class="aligncenter" title="WTFArticle.png" src="https://blog.xojo.com/wp-content/uploads/2016/01/WTFArticle.pngt1466486449161ampwidth480ampheight742" sizes="auto, (max-width: 480px) 100vw, 480px" alt="WTFArticle.png" width="480" height="742" /></p>
<p>Take a look at the full API to see what other cool features you can add to the app. Here are some suggestions:</p>
<ul>
<li>Display a random article</li>
<li>Display more than the last 8 recent articles</li>
<li>Cache the article contents on the device and use the cache when the article is displayed again</li>
<li>Display articles by month/year</li>
</ul>
<p><!--HubSpot Call-to-Action Code --> <span id="hs-cta-wrapper-7bcc3f87-4442-4a30-90b2-c9264729660a" class="hs-cta-wrapper"> <span id="hs-cta-7bcc3f87-4442-4a30-90b2-c9264729660a" class="hs-cta-node hs-cta-7bcc3f87-4442-4a30-90b2-c9264729660a"><br />
<!-- [if lte IE 8]>


<div id="hs-cta-ie-element"></div>


<![endif]--> <a href="http://blog.xojo.com/2015/10/01/cats-up-using-httpsocket-with-the-cat-rest-api/" target="_blank" rel="noopener"><img loading="lazy" decoding="async" id="hs-cta-img-7bcc3f87-4442-4a30-90b2-c9264729660a" class="hs-cta-img aligncenter" style="border-width: 0px; margin: 0 auto; display: block; margin-top: 20px; margin-bottom: 20px;" src="https://blog.xojo.com/wp-content/uploads/2016/01/7bcc3f87-4442-4a30-90b2-c9264729660a.png" alt="Use HTTPSocket with Cat REST API" width="432" height="73" align="middle" /></a></span></span> <!-- end HubSpot Call-to-Action Code --></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Generating Xojo Code From Paw</title>
		<link>https://blog.xojo.com/2016/01/06/generating-xojo-code-from-paw/</link>
		
		<dc:creator><![CDATA[Greg O'Lone]]></dc:creator>
		<pubDate>Wed, 06 Jan 2016 00:00:00 +0000</pubDate>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[PAW]]></category>
		<category><![CDATA[REST]]></category>
		<guid isPermaLink="false">http://blogtemp.xojo.com/2016/01/06/generating-xojo-code-from-paw/</guid>

					<description><![CDATA[Easy HTTP RESTful requests in Xojo and Paw]]></description>
										<content:encoded><![CDATA[<p>At Xojo, we work with a lot of HTTP REST APIs. So many in fact that I&#8217;ve spent time creating custom test harnesses to make sure that whatever I was currently coding would be compatible as well as being a test suite just in case the API changed in some subtle way (whether it be a bug fix or an API refactor gone awry). The problem with the custom test harnesses is that they&#8217;re not very portable and you end up having to create a new one for each API that you interface with.</p>
<p><span id="more-274"></span></p>
<p>When we created the iOS app for XDC 2015 last spring, I decided to take a different route and try out a few of the commercial REST API clients to see if any of them would make my life easier. The one I settled on was <a href="https://luckymarmot.com/paw" target="_blank" rel="nofollow noopener">Paw from LuckyMarmot</a>, primarily for its support of extensions written in JavaScript.</p>
<p><img loading="lazy" decoding="async" style="display: block; margin-left: auto; margin-right: auto;" title="PAW.png" src="https://blog.xojo.com/wp-content/uploads/2016/01/PAW.pngt1466486449161ampwidth253ampheight268" sizes="auto, (max-width: 253px) 100vw, 253px" alt="PAW.png" width="253" height="268" /></p>
<p>There is a <a href="https://luckymarmot.com/paw/extensions/" target="_blank" rel="nofollow noopener">small library</a> of extensions available on the Paw website, most of which are for code examples and that got me thinking&#8230; why not have examples of the request in Xojo code, both old and new framework so that I don&#8217;t need to do that by hand every time.</p>
<p><strong>Examples</strong></p>
<p>For the sake of this example, let&#8217;s say that we&#8217;re making a request to login to a fictitious API. The URL of this request is https://www.example.com/api/login, it expects that you will pass the username (name) and password (1234) as URL parameters and that a preshared key is to be included in the body of the request as JSON.</p>
<p>Paw comes with an extension for creating cURL requests and the output of that extension looks like this:</p>
<pre>curl -X "GET" "https://www.example.com/api/login?username=name&amp;password=1234" 
 -H "Content-Type: application/json" 
 -d "{"preshared-key":"QU^k9h36zdF8nx7Y"}"</pre>
<p>Using our Paw extensions, the Old Framework Xojo extension generates code that looks like this:</p>
<pre>// Login (Old Framework)

// Set up the socket
dim h as new HTTPSecureSocket
h.Secure = True
h.ConnectionType = h.TLSv12
h.setRequestHeader("Content-Type","application/json")

// JSON
Dim js As New JSONItem
js.Value("preshared-key") = "QU^k9h36zdF8nx7Y"

// Convert Dictionary to JSON Text
Dim data As String = js.toString()

// Assign to the Request's Content
h.SetRequestContent(data,"application/json")

// Set the URL
dim url as string = "https://www.example.com/api/login?username=name&amp;password=1234"

// Send Synchronous Request
dim s as string = h.SendRequest("GET",url,30)</pre>
<p>If you&#8217;re using the new framework extension, it generates code that looks like this:</p>
<pre>// Login (New Framework)

// Set up the socket
// "mySocket" should be a property stored elsewhere so it will not go out of scope
mySocket = new Xojo.Net.HTTPSocket
mySocket.RequestHeader("Content-Type") = "application/json"

// JSON
Dim d As New Dictionary
d.Value("preshared-key") = "QU^k9h36zdF8nx7Y"

// Convert Dictionary to JSON Text
Dim json As Text = Xojo.Data.GenerateJSON(d)

// Convert Text to Memoryblock
Dim data As Xojo.Core.MemoryBlock = Xojo.Core.TextEncoding.UTF8.ConvertTextToData(json)

// Assign to the Request's Content
mySocket.SetRequestContent(data,"application/json")

// Set the URL
dim url as Text = "https://www.example.com/api/login?username=name&amp;password=1234"

// Send Asynchronous Request
mySocket.Send("GET",url)</pre>
<p>These extensions are available for download using the link below. Once downloaded, extract the folders into the Paw Extensions folder which you can reach by going to the Paw menu and selecting Extensions-&gt;Open Extensions Directory. Once they&#8217;re in there, you can make them available by selecting Extensions-&gt;Reload All Extensions.</p>
<p>Versions for the Classic Framework and Xojo Framework are available on GitHub:</p>
<ul>
<li><a href="https://github.com/xojo/Paw-XojoClassicGenerator">Paw Extension for HTTPSocket</a></li>
<li><a href="https://github.com/xojo/Paw-XojoiOSGenerator">Paw Extension for Xojo.Net.HTTPSocket</a></li>
<li><a href="https://github.com/xojo/Paw-XojoURLConnectionGenerator">Paw Extension for URLConnection</a></li>
</ul>
<p><strong>CONCLUSION:</strong></p>
<p>Paw is an excellent tool for storing and managing API configurations and examples, plus adding the ability to copy and paste Xojo HTTP socket code makes it an even better part of your library if you work with a lot of HTTP RESTful APIs.<!-- end HubSpot Call-to-Action Code --></p>
<hr />
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Test Web Services with RESTy</title>
		<link>https://blog.xojo.com/2015/08/21/test-web-services-with-resty/</link>
		
		<dc:creator><![CDATA[Paul Lefebvre]]></dc:creator>
		<pubDate>Fri, 21 Aug 2015 00:00:00 +0000</pubDate>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[HTTPSocket]]></category>
		<category><![CDATA[REST]]></category>
		<guid isPermaLink="false">http://blogtemp.xojo.com/2015/08/21/test-web-services-with-resty/</guid>

					<description><![CDATA[Use this simple Xojo project to test REST web service calls.]]></description>
										<content:encoded><![CDATA[<p><strong><em>This post was updated in March 2023 in <a href="https://blog.xojo.com/2023/03/07/testing-rest-based-web-services/">Testing REST-based Web Services</a>.</em></strong></p>
<p>Communicating with web services is fun and easy with Xojo. But sometimes it&#8217;s not so easy to test the actual REST API calls. As part of preparing materials for the HTTPSocket webinar, I created a simple app in Xojo that lets you test REST APIs. I call it RESTy.</p>
<p><span id="more-325"></span></p>
<p>RESTy uses <a href="http://developer.xojo.com/xojo-net-httpsocket">Xojo.Net.HTTPSocket</a> to send a request to a web service and get a result. If the result is text (JSON, for example) it displays in the <strong>Response</strong> tab. Here, I am calling the <a href="http://developer.xojo.com/eddies-electronics-web-service">Eddie&#8217;s Electronics web service</a> to return a list of all the customers by specifying the URL and clicking the Fetch button:</p>
<p><img decoding="async" style="width: 525px;" src="https://blog.xojo.com/wp-content/uploads/2015/08/RESTy.pngt1466486449161ampwidth525" sizes="(max-width: 525px) 100vw, 525px" alt="RESTy" width="525" /></p>
<p>For other data (binary data such as pictures) you can use the Fetch to File button to save the request to a file.</p>
<p>The Authentication tab is used to provide Basic Authentication should the web service require it.</p>
<p>The Request Content tab can be used to provide Content data that the request might need. For example, the <a href="http://demos.xojo.com/EEWeb/" target="_blank" rel="noopener">Eddie&#8217;s Electronics</a> web service also lets you request the details for a specific customer by providing simple JSON containing the customer ID. For example:</p>
<pre>{"ID": 10039}</pre>
<p>You can put this JSON in the Request Content tab and then call the web service to get the customer information using this URL (be sure to select POST as the method type):</p>
<pre>http://demos.xojo.com/EEWS/index.cgi/special/GetCustomer</pre>
<p>To be sure, RESTy is very simple, but you have the source code so feel free to add features to it!</p>
<ul>
<li><a href="http://files.xojo.com/BlogExamples/RESTy.xojo_binary_project.zip">Download RESTy Project</a></li>
</ul>
<p>If you&#8217;re looking for something with more features, there are also commercial products to test REST web services. Here are a few:</p>
<ul>
<li><a href="https://luckymarmot.com/paw">Paw</a></li>
<li><a href="https://itunes.apple.com/us/app/do-http/id887133786?mt=12">Do Http</a></li>
<li><a href="http://restscratchpad.com">REST Scratchpad</a></li>
</ul>
<p>If you know of others, let me know in the comments.</p>
<p>Want to learn more about Xojo.Net.HTTPSocket and web services?</p>
<p><span id="hs-cta-wrapper-80e618e0-e34d-4b07-8ed3-d3ac8eed66ae" class="hs-cta-wrapper"><span id="hs-cta-80e618e0-e34d-4b07-8ed3-d3ac8eed66ae" class="hs-cta-node hs-cta-80e618e0-e34d-4b07-8ed3-d3ac8eed66ae"><!-- [if lte IE 8]>


<div id="hs-cta-ie-element"></div>


<![endif]--> <a href="http://developer.xojo.com/webinar-httpsocket" target="_blank" rel="noopener"><img loading="lazy" decoding="async" id="hs-cta-img-80e618e0-e34d-4b07-8ed3-d3ac8eed66ae" class="hs-cta-img aligncenter" style="border-width: 0px; margin: 0 auto; display: block; margin-top: 20px; margin-bottom: 20px;" src="https://blog.xojo.com/wp-content/uploads/2015/05/80e618e0-e34d-4b07-8ed3-d3ac8eed66ae.png" alt="Watch the HTTPSocket Video" width="635" height="97" align="middle" /></a> </span><script src="https://js.hscta.net/cta/current.js" charset="utf-8">// <![CDATA[
<script type="text/javascript"><![CDATA[ hbspt.cta.load(608515, '80e618e0-e34d-4b07-8ed3-d3ac8eed66ae', {}); // ]]&gt;</script></span><br />
<!-- end HubSpot Call-to-Action Code --></p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
