# What is the best way to provide support for an unknowable number of StackExchange sites?

I just wrote an app for Chrome extensions and received a request to make it cross-StackExchange compatible. If there's eventually going to be more sites than just the few listed and I don't really know what they'll be called other than by checking here every so often to see what is supported, how do I future-proof my app to work with every SE site? Or am I doomed to hardcode everything?

-

http://stackauth.com/1.0/sites will get you information about all the sites.

-
++ for digging and providing a correct and current answer for future askers. –  Sky Sanders Sep 13 '10 at 4:15

I wrote a Chrome extension myself (details here) that works against all of the Stack sites, and an approach that I found pretty useful was to maintain a simple javascript object that stores anything about the sites that I may need to access. Here's the snippet I'm currently using:

var siteDetails = [
{
siteName: "MetaStackOverflow",
siteUrlMatch: /.*meta.stackoverflow.com.*/,
iconUrl: "http://sstatic.net/mso/favicon.ico",
apiRoot: "http://api.meta.stackoverflow.com/0.8/"
},
{
siteName: "StackOverflow",
siteUrlMatch: /.*stackoverflow.com.*/,
iconUrl: "http://sstatic.net/so/favicon.ico",
apiRoot: "http://api.stackoverflow.com/0.8/"
},
{
siteName: "SuperUser",
siteUrlMatch: /.*superuser.com.*/,
iconUrl: "http://sstatic.net/su/favicon.ico",
apiRoot: "http://api.superuser.com/0.8/"
},
{
siteName: "ServerFault",
siteUrlMatch: /.*serverfault.com.*/,
iconUrl: "http://sstatic.net/sf/favicon.ico",
apiRoot: "http://api.serverfault.com/0.8/"
}
];


Extending this to include future StackExchange sites or even user submitted sites would be pretty trivial with a helper method.

I'm personally choosing which API I'm using by investigating the URL of the page the user is visiting, but if the user is selecting which sites to use or activate, including a simple boolean flag with the site structure would suffice.

-
yeah i saw your extension just a few seconds ago :) also, i had this idea (or something similar) on my bike ride to work this morning. it sucks we have to do something like this, but i feel like this may be the best solution right now –  Jason Jun 3 '10 at 17:08
Right now I'm working on encapsulating all that functionality into a centralized JS script, with the hopes that if / when a discovery API is implemented, I can change everything in one place and it will be implemented across my extension. Once that happens, I'll be sure to remember you and drop you a comment. –  Ryan Brunner Jun 3 '10 at 17:33
awesome, thanks man –  Jason Jun 3 '10 at 19:41