how to use put() for update request

Asked on June 02, 2017
i want to update by using put method

Replied on June 03, 2017
Find the client code snippet to use Angular Http.put()

articleUrl = "http://localhost:8080/user/article";
updateArticle(article: Article):Observable<number> {
    let cpHeaders = new Headers({ 'Content-Type': 'application/json' });
    let options = new RequestOptions({ headers: cpHeaders });
    return this.http.put(this.articleUrl, article, options)
          .map(success => success.status)

If at server side we are using Spring then we can accept the PUT request as following.

public ResponseEntity<Article> updateArticle(@RequestBody Article article) {
return new ResponseEntity<Article>(article, HttpStatus.OK);

Find the link for complete detail.

Write Answer

©2023 | Privacy Policy | Contact Us