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:
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | 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.