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)
          .catch(this.handleError);

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


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


Find the link for complete detail.



Write Answer










©2024 concretepage.com | Privacy Policy | Contact Us