Skip to content Skip to sidebar Skip to footer

Consuming Custom Request Methods With Android

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, as per

Solution 1:

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:

HttpClientclient=newHttpClient;
//...//...HttpSearchsearch=newHttpSearch;
//...
client.execute(search);

Post a Comment for "Consuming Custom Request Methods With Android"