Using custom query methods with Android

When developing an API, there is a requirement to provide custom request methods that make sense to the consumer of the API (developer). A "standard" set of query methods according to RFC-2616 :

  • Get
  • Put
  • Post
  • DELETE
  • TRACE
  • CONNECT

I would like to add another one called SEARCH . In an API, using PHP or Java, this is easy to implement in PHP. Consuming this new request method is proving to be a problem for the android and iOS developer.

IN:

  • Javascript [works through jQuery or XDomainRequest]
  • Java [works through HttpUrlConnection]
  • PHP [works through cURL]:

Working example:

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

Does not work:

  • iOS
  • Android [my guess is that this should work fine if I have a working Java example)

Does anyone have links to working examples or frameworks that will support a custom query method like SEARCH or FOOBAR ?

respectfully

+4
source share
1 answer

On Android, if you use the bundled Apache Httpclient library, you can create your own HTTP method by extending the HttpRequestBase . In fact, the classes for all standard HTTP methods ( HttpGet , HttpPost , etc.) in this library are distributed from the same class.

If your SEARCH method is very "similar" to any of the existing methods, you can directly extend this class. For example, to illustrate, suppose it is very close to the GET method. You can then create an HttpSearch class that extends HttpGet , and then customizes the implementation by overriding the appropriate methods.

After you finish the implementation of HttpSearch using it, you use the standard HttpGet class:

 HttpClient client = new HttpClient; //... //... HttpSearch search = new HttpSearch; //... client.execute(search); 
+1
source

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


All Articles