Tag Archives: REST

xnegc-logo.png.pagespeed.ic.x2isytmiK_

New England GiveCamp 2014 This Weekend

I’ll be at New England GiveCamp this weekend, helping Generations Inc., a Boston-based charity that couples literacy volunteers with those in need.

The GiveCamp movement promotes hackathons to assist charities with their technical needs. Mostly, New England GiveCamp creates and overhauls websites; but there are a number of other projects out there.

This year, I’ll be creating an interface to accept volunteer applications from Generations Inc.’s website and put those into their Salesforce CRM application. Thankfully, Salesforce has a robust developer support portal, which includes both excellent documentation and a fully functional sandbox, so early indications are that troubles should be few and far between. Knock on silicone.

As always, I’ll post a recap. Until then, you can follow along with GiveCamp on Twitter, hashtag #negc2014.

All links in this post on delicious: https://delicious.com/dougvdotcom/new-england-givecamp-2014-this-weekend

Displaying Selected YouTube Data API Thumbnails On A Web Page Via ASP.NET Web Forms

Previously, I blogged about “Displaying Selected YouTube Video Thumbnails On An ASP.NET Web Forms Page,” when you know the video IDs of the thumbnails you want to hyperlink.

A reader recently asked me how to hyperlink YouTube video thumbnails based on searching for a keyword. I promised to address that, so here goes.

Interestingly enough, searching the YouTube Data API is accomplished in a REST-like manner quite similar to the methodology I used for shortening URLs in ASP.NET via the bit.ly API.

  • Form a simple request URL to the YouTube Data API that contains the appropriate search parameters;
  • Use a WebRequest to send that URL to Google, which returns an XML document with results;
  • Use WebResponse to dump that stream into an XmlDocument;
  • Use XPath and XmlNode‘s SelectNodes method to recursively get the thumbnails from each entry; and
  • Bind up a pile of Hyperlink controls, which are added dynamically to a Panel control.

Sounds more complicated than it actually is. Let’s do it.
Continue reading

Getting QueryString Values From A Rewritten URL / ASP.NET Routing URL

During today’s similcast of the ASP.NET Firestarter in Atlanta, G. Andrew Duthie discussed .NET 4′s new support for routing — or, what everyone in Web development calls “URL rewriting.” *

Someone online asked, “If I use routing, can I access query string variables using JavaScript?”

The question isn’t as confused as it sounds on the surface. Of course, if one uses routing / URL rewriting, it’s to remove query string variable and make them part of what appears to be a permanent file structure.

In other words, this:

http://www.server.com/path/to/file.aspx?v1=foo&v2=bar

Becomes this:

http://www.server.com/path/to/file/v1/foo/v2/bar/

The questioner really means, is there a way, after rewriting a URL, to extract key->value pairs from it via JavaScript? The answer is yes; rather than using the location.search property, which allows JavaScript to get the querystring parameters of a URL, we use location.pathname to get the part of the URL that follows the domain, and use that to create our key->value pairs.

Continue reading

MSDN Northeast Roadshow, Augusta, ME, May 11, 2010 Recap

After the nearly complete disappointment of Launch 2010 Boston, I had given serious thought to not going to the MSDN Northeast Roadshow stop in Augusta, ME on Tuesday, May 11. I figured it would be little more than a regurgitation of what happened at last month’s event.

I’m glad I decided to go. What a huge difference.

In  half the time, Jim O’Neil and Chris Bowen provided immeasurably more valuable and interesting information about Visual Studio 2010 and changes to Silverlight, multithreading, ASP.NET and an overview of Windows Phone 7. Here’s a recap.

Silverlight 4: Lately, listening to Microsoft describe a new Web technology brings to mind the phrase “a day late and a dollar short.” That’s certainly the case with Silverlight 4.

Admittedly, Microsoft has shifted the emphasis behind Silverlight to be less a clone of Flash and more an extension to the Web of Windows Presentation Foundation. But the “new features” O’Neil described on Tuesday were very much old technologies for Flash, and pretty much obsolete tech given HTML5.

Specifically, Silverlight 4 supports Web cams and microphones; TCP/UDP; printing; and a multiple-trust-level model that includes access to the file system, cross-domain requests and COM integration. Additionally, the XAML one writes to render Silverlight, while still different from WPF XAML, is a lot more like WPF.

Silverlight is, therefore, weaker than Flash and stronger than it at the same time. But it seems mostly moot, given that Flash itself is falling out of favor in response to the HTML5 specification’s API support for audio, video and other complex objects. Admittedly, there are things one can do in Silverlight — namely, presenting stored data and integrating existing COM components, such as text-to-speech or an interface to a proprietary business object / program — that one cannot do directly in HTML5.

That seems to me more likely to matter when making a corporate intranet or the like. I didn’t see much hope for Silverlight when it was introduced in 2007, and I still don’t see a future for it.

Continue reading

Shortening URLs With The bit.ly API Via ASP.NET

After yesterday’s post on using the Twitter API to post status updates on Twitter from an ASP.NET application, a follower of my client suggested using a URL shortening service to link to the articles headlines being posted as tweets.

That was an excellent idea of which I should have thought in the first place. And thanks to the extreme simplicity of the REST-like bit.ly API, shortening URLs is as simple as sending a request URL laced with querystring variables.

So here is a quick and simple ASP.NET subroutine, written in VB.NET, to shorten URLs with the bit.ly API:

Sub BitlyIt(ByVal strUser As String, ByVal strAPIKey As String, ByVal strLongUrl As String)
	'This subroutine requires your page to have a label control named lblStatus

	'build URL to shorten method resource
	Dim strUri As New StringBuilder("http://api.bit.ly/shorten?")
	strUri.Append("version=2.0.1")
	'we want to get an XML response back from bit.ly, not the default JSON
	strUri.Append("&format=xml")
	strUri.Append("&longUrl=")
	strUri.Append(Server.HtmlEncode(strLongUrl))
	strUri.Append("&login=")
	strUri.Append(Server.HTMLEncode(strUser))
	strUri.Append("&apiKey=")
	strUri.Append(Server.HTMLEncode(strAPIKey))

	'create request for shorten resource
	Dim objRequest As HttpWebRequest = WebRequest.Create(strUri.ToString())
	'since we are passing querystring variables, our method is get
	objRequest.Method = "GET"
	'act as though we are sending a form
	objRequest.ContentType = "application/x-www-form-urlencoded"
	'don't wait for a 100 Continue HTTP response from bit.ly
	objRequest.ServicePoint.Expect100Continue = False
	'since we are using get, we need not send a request body; set content-length to 0
	objRequest.ContentLength = 0

	'we need to capture the XML being sent in response
	'read the response into a new XML document
	Dim objResponse As WebResponse = objRequest.GetResponse()
	Dim objXML As New XmlDocument()
	objXML.Load(objResponse.GetResponseStream())

	'the response will have three node values we're primarily interested in
	'the errorCode node will contain a numeric error code; 0 means success
	Dim nErrorCode As XmlNode = objXML.SelectSingleNode("//errorCode")
	'if there was an error, the errorMessage node will contain a user-friendly message useful for debugging
	Dim nErrorMsg As XmlNode = objXML.SelectSingleNode("//errorMessage")
	'if all went well, shortUrl will contain the full short URL created for our link
	Dim nShortUrl As XmlNode = objXML.SelectSingleNode("//shortUrl")

	'if we didn't get an errorCode value of 0, there was a problem; report the user-friendly message
	'on success, report the short URL for our resource
	If nErrorCode.InnerText <> "0" Then
		lblStatus.Text = "Error returned. Code: " & nErrorCode.InnerText & "; Message: " & nErrorMsg.InnerText
	Else
		lblStatus.Text = nShortUrl.InnerText
	End If
End Sub

Continue reading