How to make Patch Request to server on Android

How to make Patch Request to server on Android

What’s a Patch request?
On Android, we generally use 4 types of HTTP requests during server side communication; POST, GET, PUT and DELETE. PATCH isn’t one of them. It requests a set of changes described in the request entity to be applied to the resource identified by the Request-URI. You can use this in case you want to update only one field of a resource; saving bandwidth compared to using the PUT request.

Code snippet:

[code language=”html”]
JsonObjectRequestpatchRequest = new JsonObjectRequest(Request.Method.POST,url, jsonObject,
newResponse.Listener<JSONObject>()
{
@Override
public void onResponse(JSONObject response) {
// display response
// Log.d("Response", response.toString());

}
},
newResponse.ErrorListener()
{
@Override
public void onErrorResponse(VolleyError error) {
Log.d("Error.Response", error.getMessage());

}
}
){
@Override
public Map<String, String>getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("X-HTTP-Method-Override","PATCH");
headers.put("Content-Type","application/json");
return headers;
}
};
MyApplication.getInstance().getRequestQueue().add(patchRequest);
[/code]

We, at Andolasoft are experts in developing glitch free, seamless & cost-effective Android apps. If you have an idea, please share to us and let’s have a talk to take it from there.

Also, please share your suggestions below.

Tags:
,
Jay
Jayadev Das
jayadev.das@andolasoft.com

Do what you do best in – that’s what I’ve always believed in and that’s what I preach. Over the past 25+ years (yup that’s my expertise ‘n’ experience in the Information Technology domain), I’ve been consulting to small, medium and large companies ‘bout Web Technologies, Mobile Future as well as on the good-and-bad of tech. Blogger, International Business Advisor, Web Technology Expert, Sales Guru, Startup Mentor, Insurance Sales Portal Expert & a Tennis Player. And top of all – a complete family man!

Shares