You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<rulename="MissingHttpResponseStatus"since="0.2.0"language="java"externalInfoUrl="https://github.com/dgroup/arch4u-pmd/discussions/..."message="Avoid endpoints for create action without HTTP response code 201 in case of success: https://github.com/dgroup/arch4u-pmd/discussions/..."class="io.github.dgroup.arch4u.pmd....">
<priority>3</priority>
<properties>
<propertyname="annotations"value="org.springframework.web.bind.annotation.PutMapping|org.springframework.web.bind.annotation.PostMapping"/>
<propertyname="responseCodes"value="org.springframework.http.HttpStatus.CREATED"/>
<propertyname="methods"value="^create.+$"
</properties>
</rule>
Why?
According to HTTP standard for response codes once entity successfully created the endpoint should return 201 response code.
@PutMapping("/employees/{id}") // violation as no response codepublicResponseEntity<Employee> create(@Valid@RequestBodyEmployeeemployee) {
// ...
}
@ResponseStatus(HttpStatus.CREATED)
@PutMapping("/employees/{id}") // ok, response code is herepublicResponseEntity<Employee> create(@Valid@RequestBodyEmployeeemployee) {
// ...
}
@PutMapping("/employees/{id}") // ok, as method has no 'creation' semanticpublicResponseEntity<Employee> processIt(@Valid@RequestBodyEmployeeemployee) {
// ...
}
dgroup
changed the title
New rule: create with putmapping without response status 201
New rule: entity creation endpoints with putmapping/postmapping without response status 201
Apr 9, 2022
Summary
Rule definition
Why?
According to HTTP standard for response codes once entity successfully created the endpoint should return
201
response code.Read more
The text was updated successfully, but these errors were encountered: