Showing posts with label delete request. Show all posts
Showing posts with label delete request. Show all posts

Friday, 20 September 2019

RestTemplate: DELETE Request Example


public static ResponseEntity<String> delete(String url, Map<String, String> headers) {
 if (url == null || url.isEmpty()) {
  return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY).body("URL must not be null");
 }

 HttpHeaders httpHeaders = getHeadersFromMap(headers);

 HttpEntity<Object> httpEntity = new HttpEntity<Object>(httpHeaders);

 return REST_TEMPLATE.exchange(url, HttpMethod.DELETE, httpEntity, String.class);

}
You can get the complete working application from this link.



Previous                                                    Next                                                    Home

Sunday, 18 August 2019

HTTPie: DELETE: Delete an entity


Syntax
http DELETE {url}

Get all the guests
$http GET http://localhost:8080/public/v1/guests
HTTP/1.1 200 
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Content-Type: application/json;charset=UTF-8
Date: Fri, 02 Aug 2019 11:45:29 GMT
Expires: 0
Pragma: no-cache
Transfer-Encoding: chunked
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block

[
    {
        "firstName": "Siva",
        "id": 5,
        "lastName": "Nzv"
    },
    {
        "firstName": "rashika",
        "id": 6,
        "lastName": "gun"
    }
]


Delete guest with id 5
$http DELETE http://localhost:8080/public/v1/guests/5
HTTP/1.1 200 
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Content-Type: application/json;charset=UTF-8
Date: Fri, 02 Aug 2019 11:46:09 GMT
Expires: 0
Pragma: no-cache
Transfer-Encoding: chunked
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block

"OK"

$
$http GET http://localhost:8080/public/v1/guests
HTTP/1.1 200 
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Content-Type: application/json;charset=UTF-8
Date: Fri, 02 Aug 2019 11:46:13 GMT
Expires: 0
Pragma: no-cache
Transfer-Encoding: chunked
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block

[
    {
        "firstName": "rashika",
        "id": 6,
        "lastName": "gun"
    }
]




Previous                                                    Next                                                    Home