sdolgy
sdolgy

Reputation: 7001

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 RFC-2616 are:

I would like to add another, called SEARCH. On the API, using PHP or Java, this is easy to implement in PHP. The consumption of this new request method is proving to be a challenge for an android and iOS developer.

Working:

Working Example:

 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'SEARCH');

Not Working:

Does anyone have any references to working examples or frameworks that will support a custom request method, such as SEARCH, or FOOBAR?

Kind regards

Upvotes: 4

Views: 755

Answers (1)

curioustechizen
curioustechizen

Reputation: 10672

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);

Upvotes: 1

Related Questions