Dark Hydra
Dark Hydra

Reputation: 275

Spring, POST different models on the same URL

How to process different models from POST request on the same URL?

For example, I have field action in the user model.

If action equals to edit, I know, that user sent me model for editing entity.

If action equals to delete, I know, that there are other fields and other model.

How to do this on the same URL and don't use any optional GET parameters?

Upvotes: 2

Views: 209

Answers (1)

Nazgul
Nazgul

Reputation: 1902

Normally for REST based URL nomenclature the operation (PUT, DELETE, GET etc) is decided by the URI and not my the model. So if you follow the right conventions then DELETE and PUT operations should be different actions on your controller. But if you want to push the operation inside the model then you probably don't need multiple actions. Single action with a single request mapping can consume the user model and then in your service or helper you can do an if else check on the model's action attribute to see what to do about it.

Upvotes: 1

Related Questions