<?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>HTTP &#8211; Xojo Programming Blog</title>
	<atom:link href="https://blog.xojo.com/tag/http/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.xojo.com</link>
	<description>Blog about the Xojo programming language and IDE</description>
	<lastBuildDate>Tue, 07 Mar 2023 16:46:28 +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>Write a Slackbot in Less Than 20 Lines of Code</title>
		<link>https://blog.xojo.com/2016/01/12/write-a-slackbot-in-less-than-20-lines-of-code/</link>
		
		<dc:creator><![CDATA[Paul Lefebvre]]></dc:creator>
		<pubDate>Tue, 12 Jan 2016 00:00:00 +0000</pubDate>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Cats]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[Slack]]></category>
		<category><![CDATA[Web Service]]></category>
		<guid isPermaLink="false">http://blogtemp.xojo.com/2016/01/12/write-a-slackbot-in-less-than-20-lines-of-code/</guid>

					<description><![CDATA[Learn how to create a Slackbot for Slack in just a few lines of Xojo code.]]></description>
										<content:encoded><![CDATA[<p><strong>What is Slackbot?</strong></p>
<p>Slack has an API called &#8220;slash commands&#8221; that lets a user type a slash (/) followed by a command name in order to perform a special action. For example, Slack has <a href="https://get.slack.help/hc/en-us/articles/201259356-Using-slash-commands">many built-in slash commands</a>, one example is /help. Here&#8217;s how you can easily add your own slash commands using a Xojo web app and the HandleSpecialURL (or HandleURL) method.</p>
<p>Your slash command makes an HTTP request to your Xojo web service app. The web services does its thing and then returns the result back to Slack to display.</p>
<h2><span id="more-288"></span>A Xojo Web Service</h2>
<p>For demonstration, I&#8217;m going to show you how to create a Slackbot that returns a &#8220;cat fact&#8221;. The slash command will be /catfact. When you use the /catfact command, Slack calls a Xojo web service which then makes a call to the <a href="http://catfacts-api.appspot.com/doc.html">Cat Fact API</a>, parses the resulting JSON and returns an interesting cat fact back to Slack to display in your channel.</p>
<p><img decoding="async" style="width: 320px; display: block; margin-left: auto; margin-right: auto;" title="coding_cat.png" src="https://blog.xojo.com/wp-content/uploads/2016/01/coding_cat.pngt1466486449161ampwidth320" sizes="(max-width: 320px) 100vw, 320px" alt="coding_cat.png" width="320" /></p>
<p>As I&#8217;ve covered in a couple <a href="http://developer.xojo.com/webinar-web-services">Web Services webinars</a> last year, it is pretty easy to make a web service using Xojo. For this example, create a new web project and name it CatFact.</p>
<p>First you will create a simple method that will fetch a Cat Fact. Create a method on the App object, <strong>GetCatFact As String</strong>, with this code:</p>
<pre>// New request came in, so create a new HTTPSocket
Dim catSocket As New HTTPSocket

// Get a cat fact and wait for it to be returned
Dim factData As String = catSocket.Get("http://catfacts-api.appspot.com/api/facts?number=1", 30)

// Once the cat fact is returned, parse the JSON and send it to the original requester.
Dim jsonText As Text = DefineEncoding(factData, Encodings.UTF8).ToText
Dim jsonDict As Xojo.Core.Dictionary = Xojo.Data.ParseJSON(jsonText)
Dim facts() As Auto = jsonDict.Value("facts")

// Extract the fact text from the JSON
Dim fact As Text
If facts.Ubound &gt;= 0 Then
  fact = facts(0)
End If

Return fact</pre>
<p>In this Xojo project you&#8217;ll now create a simple web page UI to test that calling the Cat Fact API works. On the default page (WebPage1), add a Button and a TextField. In the Button&#8217;s Action event handler, add this code:</p>
<pre>CatFactArea.Text = App.GetCatFact</pre>
<p>Run the web app and on click the button. You should see a cat fact appear in the Text Area. The fact I got was:</p>
<p><strong>The cat has 500 skeletal muscles (humans have 650).</strong></p>
<p>Now you can add the code to process the web service request. Add the HandleSpecialURL event to the App object and use this code:</p>
<pre>If Request.Path = "CatFact" Then
  Request.Print(GetCatFact)
  Return True
End If</pre>
<p>You can test this by running the web project and then in a new tab entering the API URL, which displays a cat fact in the browser:</p>
<pre>http://127.0.0.1:8080/api/CatFact</pre>
<h2>Hook Up Web Service to Slack</h2>
<p>Now that you know the web service works, the next step is to hook it up to Slack. But before you can do that, you have to host the web app somewhere on the Internet; Slack can&#8217;t see your local web app! For this example, I&#8217;ve published the Cat Fact web service to <a href="http://developer.xojo.com/xojo-cloud">Xojo Cloud</a> because it&#8217;s fast and easy. This is the URL to the Cat Fact web service on Xojo Cloud:</p>
<pre>http://demos.xojo.com/CatFacts/index.cgi/api/CatFact</pre>
<p>Now you need to go to your Slack team settings to <a href="https://my.slack.com/services/new/slash-commands">add a slash command</a>. On that screen you&#8217;ll want to set the name of the <strong>Command</strong> to &#8220;/catfact&#8221; and the <strong>URL</strong> to &#8220;http://demos.xojo.com/CatFacts/index.cgi/api/CatFact&#8221; (the URL from above). Also change the <strong>Customize Name</strong> field to &#8220;CatFact&#8221;. You can ignore all the other fields and click the Save Integration button at the bottom.</p>
<p>That&#8217;s it. The slash command is now active. Head on over to your Slack team and type /catfact into a channel. You&#8217;ll get back a fact from &#8220;CatFact&#8221;.</p>
<p><img fetchpriority="high" decoding="async" title="SlackbotCatFact.png" src="https://blog.xojo.com/wp-content/uploads/2016/01/SlackbotCatFact.pngt1466486449161ampwidth578ampheight151" sizes="(max-width: 578px) 100vw, 578px" alt="SlackbotCatFact.png" width="578" height="151" /></p>
<p>And it took less than 20 lines of code! You can now use this technique to integrate your own web services into Slack.</p>
<p>By default, only you will see the cat fact returned by the Slashbot; it is not broadcast to the entire channel. You can change this by returning specifically formatted JSON rather than just a text string (as described on the <a href="https://api.slack.com/slash-commands">Slack Commands API page</a>).</p>
<p>If you come up with a great slash command and want to make it available to the world, you can attach it to a <a href="https://api.slack.com/slack-apps">Slack app</a> and publish it to the <a href="https://slack.com/apps">App Directory</a>. The steps for this are also in the <a href="https://api.slack.com/slash-commands">Slash Commands API page</a>.</p>
<p style="text-align: center;"><!--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"><img decoding="async" id="hs-cta-img-7bcc3f87-4442-4a30-90b2-c9264729660a" class="hs-cta-img aligncenter" style="border-width: 0px;" 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" /></a> </span><script src="https://js.hscta.net/cta/current.js" charset="utf-8">// <![CDATA[
<script type="text/javascript"><![CDATA[ hbspt.cta.load(608515, '7bcc3f87-4442-4a30-90b2-c9264729660a', {});
// ]]&gt;</script></span><br />
<!-- 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 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="(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>Formatting SQL With A Web Service</title>
		<link>https://blog.xojo.com/2015/10/28/formatting-sql-with-a-web-service/</link>
		
		<dc:creator><![CDATA[Paul Lefebvre]]></dc:creator>
		<pubDate>Wed, 28 Oct 2015 00:00:00 +0000</pubDate>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Web Service]]></category>
		<guid isPermaLink="false">http://blogtemp.xojo.com/2015/10/28/formatting-sql-with-a-web-service/</guid>

					<description><![CDATA[Formatting SQL for display can sometimes be a pain, particularly for the many different flavors of SQL. One easy way to do the formatting is to use a web service.]]></description>
										<content:encoded><![CDATA[<p>Formatting SQL for display can sometimes be a pain, particularly for the many different flavors of SQL. One easy way to do the formatting is to use a web service.</p>
<p><span id="more-273"></span></p>
<p>I did a little Google searching and found this one which seems to work well: <a href="https://github.com/sqlparser/sql-pretty-printer/wiki/SQL-FaaS-API-manual">https://github.com/sqlparser/sql-pretty-printer/wiki/SQL-FaaS-API-manual</a></p>
<p>To use it with Xojo, create a subclass of <a href="http://developer.xojo.com/xojo-net-httpsocket">Xojo.Net.HttpSocket</a> and drag it onto a window</p>
<p>This code in a button takes unformatted SQL from a TextArea and sends it to the web service, asking that it be formatted for Oracle (rqst_db_vendor=1):</p>
<pre> Dim sql As Text = SQLArea.Text.ToText
 Dim postText As Text = "rqst_input_sql=" + _
  EncodeURLComponent(sql).ToText + _
  "&amp;rqst_db_vendor=1"

 Dim postData As Xojo.Core.MemoryBlock
 postData = Xojo.Core.TextEncoding.UTF8.ConvertTextToData(postText)

 SQLFormatter1.SetRequestContent(postData, _
  "application/x-www-form-urlencoded")
 SQLFormatter1.Send("POST", _
  "http://www.gudusoft.com/format.php")

</pre>
<p>This code in the PageReceived event handler of your HttpSocket subclass parses the resulting JSON and displays the formatted SQL:</p>
<pre>Dim jsonText As Text
jsontText = Xojo.Core.TextEncoding.UTF8.ConvertDataToText(Content)
Dim json As Xojo.Core.Dictionary = Xojo.Data.ParseJSON(jsonText)
FormattedSQLArea.Text = json.Value("rspn_formatted_sql")</pre>
<p><a href="https://www.dropbox.com/s/f6xf60ew10z8saz/FormatSQLService.xojo_binary_project?dl=0">Download Sample Project</a></p>
<p>Looking for something to try next? Watch the video below and learn how to use <a href="http://developer.xojo.com/xojo-net-httpsocket">HTTPSocket</a><a href="http://developer.xojo.com/xojo-data"> </a>in the Xojo Framework.</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"><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></span></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Cats Up: Using HTTPSocket with the Cat REST API</title>
		<link>https://blog.xojo.com/2015/10/01/cats-up-using-httpsocket-with-the-cat-rest-api/</link>
		
		<dc:creator><![CDATA[Paul Lefebvre]]></dc:creator>
		<pubDate>Thu, 01 Oct 2015 00:00:00 +0000</pubDate>
				<category><![CDATA[iOS]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Cats]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[Mobile]]></category>
		<guid isPermaLink="false">http://blogtemp.xojo.com/2015/10/01/cats-up-using-httpsocket-with-the-cat-rest-api/</guid>

					<description><![CDATA[A perfect way to demonstrate HTTPSocket- the Cat API provides a REST (web services) API that can send you random cat pictures. ]]></description>
										<content:encoded><![CDATA[<p>On the Internet, everyone loves cats. Using HTTPSocket and The Cat REST API, Xojo makes it easy for you to get the cat pictures you need to brighten your day. Read on to learn how to make everyday Caturday&#8230;and for more cat puns.</p>
<p><span id="more-258"></span></p>
<p>When preparing materials for the <a href="http://developer.xojo.com/webinar-httpsocket">HTTPSocket webinar</a> I came across <a href="http://thecatapi.com/">The Cat API</a>. This wonderful site provides <a href="http://thecatapi.com/docs.html">a REST (web services) API</a> that sends you random cat pictures. What a perfect way to demonstrate <a href="http://developer.xojo.com/xojo-net-httpsocket">HTTPSocket</a>!</p>
<p>With just a few lines of code, I&#8217;m going to show you how to create an iPhone app that will show you a new cat picture each time you launch it. I call this app &#8220;Cats Up&#8221;.</p>
<p><img decoding="async" style="width: 320px; display: block; margin-left: auto; margin-right: auto;" title="Cat + Cat = Cute1" src="https://blog.xojo.com/wp-content/uploads/2015/10/Cat1.pngt1466486449161" alt="Cat + Cat = Cute1" data-constrained="true" /></p>
<h2>Set up the iOS Project</h2>
<p>Launch Xojo and create a new iOS project called &#8220;CatsUp&#8221;. Drag an ImageView control onto the View and make it fill most of the area. Drag a Button to the View and place it at the bottom with the title &#8220;Cats Up!&#8221;. The result should look like this:</p>
<p><img decoding="async" style="display: block; margin-left: auto; margin-right: auto; width: 388px;" title="ios preview cats up" src="https://blog.xojo.com/wp-content/uploads/2015/10/CatsUpLayout.pngt1466486449161" alt="ios preview cats up" data-constrained="true" /></p>
<h2>View the Cat API</h2>
<p>The <a href="http://thecatapi.com/docs.html">Cat API documentation page</a> describes the full API, but this project only needs to use the get method to get you &#8220;all the fancy cat images you can handle&#8221;. The URL for this method is:</p>
<pre>http://thecatapi.com/api/images/get</pre>
<h2>Add Code</h2>
<p>It is time to add a tiny amount of code. First, you need to create an HTTPSocket subclass.</p>
<ol>
<li>Click the Insert button on the toolbar and select Class. Name the class CatCloud.</li>
<li>Set the class Super to &#8220;Xojo.Net.HTTPSocket&#8221;.</li>
<li>Add a method to the class called GetCat with this code:</li>
</ol>
<pre>Try
  Self.Send("GET","http://thecatapi.com/api/images/get")
Catch t As UnsupportedOperationException
  Return
End Try</pre>
<p>Now select your view (View1) and drag the CatCloud class onto it. This adds it to the Shelf at the bottom on the layout editor. It will automatically be named CatCloud1.</p>
<p>Double-click CatCloud1 to add the PageReceived event handler and add this code:</p>
<pre>Dim catPic As iOSImage 
catPic = iOSImage.FromData(content)
ImageView1.Image = catPic</pre>
<p>Next double-click the button to add the Action event handler and add this code:</p>
<pre>CatCloud1.GetCat</pre>
<p>Lastly, add an Open event handler to the View and add this code:</p>
<pre>CatCloud1.GetCat</pre>
<h2>Test</h2>
<p>Run your project to launch it in the iOS Simulator. An initial cat picture should appear. Click the &#8220;Cats Up!&#8221; to show a new picture.</p>
<p><img decoding="async" style="width: 320px; display: block; margin-left: auto; margin-right: auto;" title="Cat Vader" src="https://blog.xojo.com/wp-content/uploads/2015/10/Cat_Vader.pngt1466486449161" alt="Cat Vader" data-constrained="true" /></p>
<p>May the cat be with you.</p>
<ul>
<li><a href="http://files.xojo.com/BlogExamples/Catsup.xojo_binary_project.zip">Download the iOS project</a></li>
</ul>
<p><strong>March 2022 UPDATE:</strong> Get Cats Up! for Android in the <a href="https://play.google.com/store/apps/details?id=com.xojo.catsup">Google Play Store</a>!</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>My Favorite New Xojo Framework Features</title>
		<link>https://blog.xojo.com/2015/08/26/my-favorite-new-xojo-framework-features/</link>
		
		<dc:creator><![CDATA[Paul Lefebvre]]></dc:creator>
		<pubDate>Wed, 26 Aug 2015 00:00:00 +0000</pubDate>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Xojo Framework]]></category>
		<guid isPermaLink="false">http://blogtemp.xojo.com/2015/08/26/my-favorite-new-xojo-framework-features/</guid>

					<description><![CDATA[Here are some of my favorite features of the Xojo framework.]]></description>
										<content:encoded><![CDATA[<p>The first classes in the new Xojo Framework have been available for all project types since Xojo 2015 Release 2. Here are some of my favorite features.<br>
<span id="more-304"></span></p>
<h2>Text</h2>
<p>The new Text data type is a substitute for String and has the benefit of making encodings easier to work with. Essentially if you use Text, you don&#8217;t have to worry about the encoding. When you get data from an outside source (a file, a database or even a String), you specify the encoding so it can be stored as Text. Once it is in Text, you don&#8217;t worry about the encoding. When you need to send the Text to a file, DB or elsewhere, you convert it to data using whatever encoding is appropriate- usually UTF8.</p>
<p>You can easily use Text with your existing projects as a Text value converts back to a String automatically. For example, you can set a button Caption using a Text variable:</p>
<pre>Dim t As Text = "Hello"
MyButton.Caption = t // converts automatically to String</pre>
<p>If you have a String (such as a property of a UI control) you can easily convert it to Text by calling&nbsp;the ToText method. For example, you store the Caption of a button as Text:</p>
<pre>Dim t As Text = MyButton.Caption.ToText</pre>
<h2>Dictionary</h2>
<p>I prefer <a href="http://developer.xojo.com/xojo-core-dictionary">Xojo.Core.Dictionary</a> because it is has an easy-to-use iterator, making it crazy-simply to loop through the items in&nbsp;the Dictionary:</p>
<pre>Dim myDictionary As New Xojo.Core.Dictionary
myDictionary.Value("Name") = "Bob Roberts"
myDictionary.Value("City") = "Boston"
For Each entry As Xojo.Core.DictionaryEntry In myDictionary
  Dim key As Text = entry.Key
  Dim value As Text = entry.Value
Next</pre>
<p>Xojo.Core.Dictionary can also be case-sensitive which is not even an option&nbsp;with the classic Dicitonary class! You just have to subclass (or use AddHandler) and implement the CompareKeys event handler:</p>
<pre>Dim leftText As Text = lhs
Dim rightText As Text = rhs
Return leftText.Compare(rightText, Text.CompareCaseSensitive)</pre>
<h2>JSON</h2>
<p>In the new framework, <a href="/2015/04/16/newframeworkjson/">JSON is handled by two methods</a> (<a href="http://developer.xojo.com/xojo-data$ParseJSON">Xojo.Data.ParseJSON</a> and <a href="http://developer.xojo.com/xojo-data$GenerateJSON">Xojo.Data.GenerateJSON</a>), typically with Xojo.Core.Dictionary. Creating JSON text from a Dictionary is one line of code:</p>
<pre>Dim jsonText As Text = Xojo.Data.GenerateJSON(myDictionary)</pre>
<p>And converting JSON text to a Dictionary is also one line of code:</p>
<pre>Dim jsonDict As Xojo.Core.Dictionary = Xojo.Data.ParseJSON(jsonText)</pre>
<p>Both of these methods are much faster than using JSONItem in the classic framework.</p>
<h2>HTTPSocket</h2>
<p><a href="http://developer.xojo.com/xojo-net-httpsocket">Xojo.Net.HTTPSocket</a> uses HTTP 1.1. This is a big advantage over the classic HTTPSocket which only supports HTTP 1.0 making it not always compatible with some sites.</p>
<p>I recently did a <a href="http://developer.xojo.com/webinar-httpsocket">webinar that shows how to use HTTPSocket with a variety of web services</a>.</p>
<h2>TextInputStream/TextOutputStream</h2>
<p>Lastly, I often work with Text files which means I have to deal with encodings. The <a href="http://developer.xojo.com/xojo-io-textinputstream">TextInputStream</a> and <a href="http://developer.xojo.com/xojo-io-textoutputstream">TextOutputStream</a> make it easy to deal with encodings because the encoding is part of the method calls.</p>
<p>You can even use these classes with classic FolderItems by first converting them to Xojo.IO.FolderItem. For example, this prompts the user for a file and then opens it using a TextInputStream:</p>
<pre>Dim f As FolderItem = GetOpenFolderItem("")
If f &lt;&gt; Nil Then
  Dim openFile As New Xojo.IO.FolderItem(f.NativePath.ToText)
  Dim input As Xojo.IO.TextInputStream
  input = Xojo.IO.TextInputStream.Open(openFile, Xojo.Core.TextEncoding.UTF8)
End If</pre>
<p>If you have not already, try these new Xojo Framework classes in your projects. You&#8217;ll appreciate it!</p>
<p><!-- end HubSpot Call-to-Action Code --></p>


<p>Update (June 2020):</p>



<p>Since this was posted, there have been many updates to Xojo. In particular you should check out these equivalent API 2.0 features:</p>



<ul class="wp-block-list"><li><a href="https://documentation.xojo.com/api/language/dictionary.html">Dictionary</a> now also has an iterator.</li><li><a href="https://documentation.xojo.com/api/text/json/generatejson.html">GenerateJSON</a> and <a href="https://documentation.xojo.com/api/text/json/parsejson.html">ParseJSON</a>.</li><li><a href="https://documentation.xojo.com/api/networking/urlconnection.html">URLConnection</a></li></ul>



<p></p>
]]></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>
