简体   繁体   中英

REST and compound CRUD transaction

The application has following CRUD form

在此处输入图片说明

It allows user to create, read, update and delete rows (entities with identity) within a single form and save changes in a single transaction.

In this case, is it justified to use aggregated POST request to REST? The request would look like following (request would contain just changed/added entities)

POST /api/entities/

{[
  {"id": 1, "field": "Foo"},
  {"id": 2, "field": "Bar", "deleted": true},
  {"id": 3, "field": "Baz"},
  {"field": "New 1"},
  {"field": "New 2"},
]}

I know it's not really RESTFul. Yet the UI design cannot be changed and save should be atomic transaction. Do I have better choices?

is it justified to use aggregated POST request to REST?

Using POST is fine .

I know it's not really RESTFul.

Of course it is -- that's how we do things on the web: and HTML form that describes interesting fields, processing rules that describe how a browser should construct a message-body from the field values.

The detail that you are creating some flavor of application/json representation rather than an application/x-www-form-urlencoded representation is not significant.

Your resource model is not your domain model, which is not your data model.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM