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:
- GET
- PUT
- POST
- DELETE
- TRACE
- CONNECT
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:
- Javascript [ works via JQuery or XDomainRequest ]
- Java [ works via HttpUrlConnection ]
- PHP [ works via cURL ]:
Working Example:
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'SEARCH');
Not Working:
iOS- Android [ my assumption is that this should work fine if I have a working Java example ]
Does anyone have any references to working examples or frameworks that will support a custom request method, such as SEARCH, or FOOBAR?
Kind regards
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,HttpPostetc) in this library extend from the same class.If your
SEARCHmethod 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 theGETmethod. Then you could create a classHttpSearchwhich extendsHttpGetand then customize the implementation by overriding appropriate methods.Once you have your
HttpSearchimplementation ready, using it is similar to using a standardHttpGetclass: