Create Twitter-like REST API endpoints with IIS URL rewrite

Twitter’s REST API uses endpoints that look like this:

http://www.domain.com/[object]/method.json

In addition for GET request you can append parameters like this:

http://www.domain.com/[object]/[method].json?param1=a&param2=b

So for example a call to the Twitter REST might look like this:

https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=davideedle&count=2

I wanted to try and reproduce this format with a REST API I’ve been playing with, so I spent some time figuring out how to configure IIS URL rewrite to handle these URLs and deliver the parameters to an ASP page.

You’ll need IIS rewrite installed, in IIS Manager you should see the ULR rewrite icon if you click on a website, for example:

Screen Shot 2013-09-23 at 11.30.31 AM

If the icon is not there download and install URL rewrite extension from the Microsoft website, then open URL Rewrite and add a new Inbound Rule.

Here’s the regular expression pattern I came up with:

^rest/v1/([^/]*)/([^/]*)\.json$

With the Rewrite URL of:

rest/v1/?objectTypeName={R:1}&objectMethod={R:2}

This means that a URL like this:

http://www.domain.com/myObject/myMethod.json?param1=a&param2=b

Will pass the parameters into my ASP page like this:

objectTypeName = myObject
objectMethod = myMethod
param1 = a
param2 = b

You need to make sure you have the “Append query string” option checked for the Rule so the additional parameters (eg param1 and param2) are passed through the rewrite.

Support medical research – have more helium balloons at birthday parties

up_movie_balloons_house-wide

I was listening to a radio program the other day about threats to the world’s helium suppliers, and was fascinated at the story. Like many people we love having helium balloons for our childrens’ birthday parties but it seemed, at least from the radio report, that this might be rather remarkably going to become a party favourite of the past.

A third of the world’s helium comes from a US Government stockpile in Texas, originally founded in the 1920s as a reserve for airships, and sited near gas fields that have some particularly high percentages of helium in the gas extracted.

It turns out that when natural gas is mined, it  contains traces of helium. However this is often at such a low rate that it is not commercially viable to extract, as a consequence there are only a dozen or so places around the world where helium is mined.

The big commercial problem is that the selling off of the USA’s helium reserves has artificially lowered the price of helium for decades – the price we pay is not a true reflection of the cost of the product. And now the reserve is running out, the world will have to turn to the other sources of helium – and pay the commercially viable cost.

Helium is key to many high tech machines and processes, for example it’s used in the production of semiconductors (those tiny things that make everything from your iPhone to your car work); the production of optic fibre, and the operation of Magnetic resonance imaging machines (MRI) in medicine.

At least one person, an academic in the UK, has suggested banning helium balloons from kids birthday parties, however someone with a better grounding in economics points out the flaw:

Even if the helium reserve does stay open for a few more years, its helium will be sold at much higher prices than before. As a result, average market prices could rise by about 30% in 2014, estimates Richard Clarke, a resources consultant in Oxford, UK. That comes on top of major price rises that have already squeezed research budgets. In 2000, the market price of high-quality helium was roughly £1/m3 (enough to make about 1.35 litres of liquid helium); today it hovers around £4/m3.
So what can be done? Some researchers have suggested banning frivolous uses of helium, such as party balloons. But this accounts for only 8% of global demand, and offers some of the highest profit margins in the market – without birthday balloons, researchers’ helium would likely cost even more.
So there you go, the more helium balloons at your birthday parties, the more you are supporting medical research.

If Kim Kardashian’s baby with Kanye West is called North West I’d improve my search engine rankings

If Kim Kardashian's baby with Kanye West is called North West I'd improve my search engine rankings

My random thought for the day was, if I stuff my blog post title with lots of interesting words and terms, just how many people would turn up. Sadly (perhaps promisingly) I did then have to go and check several key facts:

  • How to spell Kim Kardashian
  • Who her boyfriend is today
  • The name of Kim Kardashian’s baby (who calls their child North West? All that pops into my head is North By North West, a really rather good film from the late 1950s directed by Alfred Hitchcock).

Finally I had a quick look at the Google Trends site which gives you an idea of what lots of people are searching for at the moment. Today it turns out the top of the hit parade is:

  • NFL
  • Julius Thomas (had to look him up as well)
  • Anthony Weiner (will that man never give up?)

Which means I probably should write something like how I went to watch an NFL game with Anthony Weiner and Julius Thomas scored a goal/basket/point. Yes, just realised Thomas plays basketball and the NFL is American Football, but hey, who cares when you’re just a search engine traffic moll.

 

 

A blast from the past, apparently Peter Beattie is repeating the same online mistakes as 2004

iforgot

Out of idle curiosity, because I have no better way to spend my days and it’s hard to avoid the ‘e’ word this week, I searched my blog for any mention of the word ‘election’. The earliest post I’ve written containing that word is from 15 January 2004 (yes, I’ve been writing stuff for way too long), and was a quick note that Peter Beattie, then Queensland Premier, had called a snap election ‘Queensland Labor Online‘.

This is the main part of the post:

“There was a minor hiccup this week when an enterprising activist registered peterbeattie.com and directed it to the rival Liberal web site, but this seems to have been altered and it now goes to the teambeattie, so someone has had a word to someone. Fascinating how the media blew it up as a hack attack. Nothing of the sort of course, just a piece of online activism, and serves Beattie for not spending the few extra bucks to register the domain in the first place.”

Again, because I have nothing else to do in my long idle days, I checked both the domains peterbeattie.com and teambeattie.com.

The former leads you to site of Peter Beattie “…internet entrepreneur, motorcycle junkie and world famous hardcore porn star. (one of those might be fake)”

The latter is now sitting on a domain park, and available for purchase from whoever owns it – which I can’t tell because WHOIS shows it’s registered behind one of the domain privacy companies.

Pretty surprised some enterprising Liberal hasn’t picked up on this and taken action. And even more surprised that ‘Team Beattie’ couldn’t be bothered to pay a few bucks to renew the domain. Then again Mr Beattie did say he’d never run for political office again after stepping down as Premier in 2007, so guess wasn’t top of his mind at the time.

Time Machine: The problem may be temporary. Try again later to back up. If the problem persists, use Disk Utility to repair your backup disk

timemachine_logo

Yesterday Time Machine on my MacBook started to fail with the message:

“The problem may be temporary. Try again later to back up. If the problem persists, use Disk Utility to repair your backup disk”

It kept erroring after each hourly backup attempt. So I tried the obvious and unmounted the external HDD, turned off/on, remounted, ran backup again, no dice.

I ran Disk Utility to repair the disk, no dice.

I then found this forum post , which led me to the absolutely fantastic Pondini site (the link on the forum post is old, you need to go here) and smacked my head because I’m an idiot, I already have the Time Machine Buddy widget on my Desktop, just been so long I had forgotten.

That showed me:

“Starting standard backup
Backing up to: /Volumes/2TB/Backups.backupdb
Waiting for index to be ready (101)
2.52 GB required (including padding), 1.18 TB available
Indexing a file failed. Returned 1 for: /Library/Spotlight, /Volumes/2TB/Backups.backupdb/Apple’s MacBook Pro (2)/2013-09-03-071009.inProgress/C981E713-FC42-4A7D-BDD5-C83709DF0D5B/Macintosh HD/Library/Spotlight
Aborting backup”

Which shows that Time Machine has been choking on a Spotlight search file, which in turn led me to notice that my Spotlight seemed to be taking forever to complete an index (you can tell Spotlight is indexing, there’ll be a tiny black dot in the circle of the Spotlight magnifying glass top right of your screen).

Screen Shot 2013-09-04 at 11.01.28 AM

In fact, the hours remaining at one point said “About 11 MONTHS” remaining. Not encouraging. I know there’s a way to force Spotlight to reindex your Mac:

  • Open System Preferences
  • Click Spotlight icon
  • Click the Privacy button
  • Add your HDD to the list “Prevent Spotlight from searching these locations”
  • Close System Preferences
  • Re-open, click Spotlight icon, click Privacy button, remove your HDD from the list, close System Preferences

This should kick off a fresh index, it’s much easier than one method I figured out a while ago where you manually delete the Spotlight index file (at one stage my Spotlight decided it didn’t want to index my local hard drive, just my external drives).

So far so good. Time Machine successfully completed its last backup. Spotlight has been sporadically re-indexing, but appears to be returning correct search results when I try a few tests.