I work on a couple of projects that connect with external services like Facebook and Netflix. At this moment most libraries I'm using to access these APIs ( including the ones I've written myself ) have single methods so call specific API functions yet always seem to call some sort of base method to make the request. Something like this:
public class ExternalApi
{
public string SendMessage( criteria )
{
//do something unique to this method with criteria like
//like generating an xml statement or fql query
return SendRestRequest( modifiedCriteria );
}
public string GetData( criteria )
{
//do something unique to this method with criteria like
//like generating an xml statement or fql query
return SendRestRequest( modifiedCriteria );
}
public string SendRestRequest( modifiedCriteria )
{
//add global things to modifiedCriteria like authentication bits
//or wrapping the criteria in some xml or json shell
var request = new HttpRequest();
//make the request, return data
}
}
So my question is there a better pattern or OO principal to use here so in each singular API call method I'm not explicitly calling a base method every time?
Is what I'm looking for some kind of invocation interception pattern, like the ASP.NET MVC framework and ActionResults?
Edit 1: I'm not looking to use the features of any other service or library like Wcf. For these projects I'm only using 1-5% of these API's capabilities and prefer to roll my own code for these things.