简体   繁体   中英

RESTFul API complex object creation rollback

What is the proper way of handling partial object creation? Let's say I have a complex object, say class with sections. So i will have some endpoints like

/v1/api/classes

and

/v1/api/classes/<id>/sections

and so i will POST to the first endpoint and then a number of POSTS to the 2nd to create the entire object. What if one of the section POSTS fails? I want to rollback the entire class creation. What's the best way of handling that?

The best way to handle a larger atomic operation. POST as create is very much a convention, but what you put inside the body can be completely up to you.

I feel that's by far the easiest if you want to avoid partial creation and (temporary) invalid state.

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