Consuming Custom Request Methods with Android

前端 未结 1 556
庸人自扰
庸人自扰 2021-01-19 16:28

In developing an API, there is a requirement to provide custom request methods that make sense to a consumer of the API (developer). The \"standard\" set of request methods

相关标签:
1条回答
  • 2021-01-19 16:47

    In Android, if you use the bundled Apache Httpclient library, you can create a custom HTTP Method by extending HttpRequestBase. In fact, classes for all the standard HTTP methods (HttpGet, HttpPost etc) in this library extend from the same class.

    If your SEARCH method is very "similar" to any of the existing methods, you can directly extend that class. For instance, for the purpose of illustration, let's assume it is very close to the GET method. Then you could create a class HttpSearch which extends HttpGet and then customize the implementation by overriding appropriate methods.

    Once you have your HttpSearch implementation ready, using it is similar to using a standard HttpGet class:

    HttpClient client = new HttpClient;
    //...
    //...
    HttpSearch search = new HttpSearch;
    //...
    client.execute(search);
    
    0 讨论(0)
提交回复
热议问题