-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: return 200 (not 204) for PUT requests to entity verticles
- Loading branch information
Dapeng Wang
committed
Jun 2, 2023
1 parent
9f30e74
commit ec66efd
Showing
5 changed files
with
229 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# EntityVerticle | ||
|
||
# Create | ||
|
||
A `POST` request will be used to create a new entity. In this case, the `Future<EntityWrapper> createData(DataQuery query, DataContext context)` method of the responsible `EntityVerticle` will be invoked. | ||
According to the best-practices of REST-API, the response of such a POST-request should | ||
* contain a `Location`-header with the location of the newly created entity | ||
* return the entity representation in the response body | ||
|
||
To achieve this, a `EntityVertile` should in the `createEntity`-method | ||
* set the `Location` in the response context data | ||
``` | ||
context.responseData().put("Location", /io.neonbee.test3.TestService3/TestCars(/unique-id)); | ||
``` | ||
* return a filled `EntityWrapper` | ||
``` | ||
return Future.succeededFuture(new EntityWrapper(TEST_ENTITY_SET_FQN, createEntity(ENTITY_DATA_1)); | ||
``` | ||
In this case, a 201 status code with the entity representation will be returned in the HTTP-response. | ||
The response context data under the key `Location` will be set as HTTP-header as well. | ||
|
||
Just for backward-compatibility, a 204 status code will be returned, if no entity is returned in the `EntityWrapper` by the verticle. | ||
|
||
# Update | ||
|
||
A `PUT` request will be used to update an existing entity. In this case, the `Future<EntityWrapper> updateData(DataQuery query, DataContext context)` method of the responsible `EntityVerticle` will be invoked. | ||
According to the best-practices of REST-API, the response of such a PUT-request should return the entity representation in the response body | ||
|
||
To achieve this, a `EntityVertile` should return a filled `EntityWrapper` in the `updateEntity`-method | ||
``` | ||
return Future.succeededFuture(new EntityWrapper(TEST_ENTITY_SET_FQN, createEntity(ENTITY_DATA_1)); | ||
``` | ||
In this case, a 200 status code with the entity representation will be returned in the HTTP-response. | ||
|
||
Just for backward-compatibility, a 204 status code will be returned, if no entity is returned in the `EntityWrapper` by the verticle. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.