Best external REST API access pattern?

I am working on several projects that connect to external services such as Facebook and Netflix. At the moment, most of the libraries that I use to access these APIs (including the ones I wrote myself) have separate methods, so calling certain API functions still always calls some basic method to execute the request. Something like that:

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, is it better to use a template or OO CEO, so in each singular method of calling the API, I will not explicitly call the base method every time?

Am I looking for some kind of call pickup pattern like ASP.NET MVC framework and ActionResults?

1: , Wcf. 1-5% API .

+3
2

REST . , .

interface HTTPRequest{
  public void get();
  public void post();
  public void put();
  public void delete();
}

HTTPRequest HTTP, RestClient

interface RestClient{
  public void create();
  public void read();
  public void update();
  public void delete();
}

CRUD-. , , - RestClient, . , , . - "createResultProcessor", RestClient, ..

, , UML- , SO UML-!

0

Source: https://habr.com/ru/post/1706188/


All Articles