3,863 total views, 2 views today

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:

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

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.