@PatchMapping: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
Line 9: Line 9:


=REST=
=REST=
=REST=
<syntaxhighlight lang='java'>
@RestController
@RequestMapping(path = "/a", produces = "application/json")
public class AController {
  @PatchMapping(path = "/{id}", consumes = "application/json")
  public ResponseEntity<A> patch(@PathVariable("id") Integer id, @RequestBody A a) {
    A current = content.get(id);
    if (current == null) {
      return new ResponseEntity<>(null, HttpStatus.NOT_FOUND);
  }
    if (a.getName() != null) {
        current.setName(a.getName());
    }
    ...
    return new ResponseEntity<>(current, HttpStatus.OK);
  }
}
</syntaxhighlight>


==HTTP PATCH Semantics for REST Applications==
==HTTP PATCH Semantics for REST Applications==


{{Internal|REST_and_Hypermedia#PATCH|HTTP PATCH Semantics for REST Applications}}
{{Internal|REST_and_Hypermedia#PATCH|HTTP PATCH Semantics for REST Applications}}

Revision as of 03:00, 13 March 2019

Internal

Overview

The annotation may also contain a sub-path relative to the class-level base path, usually configured with @RequestMapping.

REST

REST

@RestController
@RequestMapping(path = "/a", produces = "application/json")
public class AController {

  @PatchMapping(path = "/{id}", consumes = "application/json")
  public ResponseEntity<A> patch(@PathVariable("id") Integer id, @RequestBody A a) {

    A current = content.get(id);

    if (current == null) {

       return new ResponseEntity<>(null, HttpStatus.NOT_FOUND);
   }

    if (a.getName() != null) {

        current.setName(a.getName());
    }

    ...
    return new ResponseEntity<>(current, HttpStatus.OK);
  }
}

HTTP PATCH Semantics for REST Applications

HTTP PATCH Semantics for REST Applications