C# class architecture for REST services

Architecturecrest

I am integrating with a set of REST services exposed by our partner. The unit of integration is at the project level meaning that for each project created on our partners side of the fence they will expose a unique set of REST services.

To be more clear, assume there are two projects – project1 and project2. The REST services available to access the project data would then be:
/project1/search/getstuff?etc…
/project1/analysis/getstuff?etc…
/project1/cluster/getstuff?etc…

/project2/search/getstuff?etc…
/project2/analysis/getstuff?etc…
/project2/cluster/getstuff?etc…

My task is to wrap these services in a C# class to be used by our app developer.

I want to make it simple for the app developer and am thinking of providing something like the following class.

class ProjectClient  
{  
  SearchClient _searchclient;  
  AnalysisClient _analysisclient;  
  ClusterClient _clusterclient;  

  string Project {get; set;}  
  ProjectClient(string _project)  
  {  
    Project = _project;  
  }  
}

SearchClient, AnalysisClient and ClusterClient are my classes to support the respective services shown above.

The problem with this approach is that ProjectClient will need to provide public methods for each of the API's exposed by SearchClient, etc…

public void SearchGetStuff()
{
  _searchclient.getStuff();
}

Any suggestions how I can architect this better?

Best Answer

Why not make it easy on your self - both decision-wise and implementation-wise - and just use one of the many frameworks that already exist to consume Web API's, like RestSharp or Hammock.

Related Topic