What if it followed an envelope style pattern, but nested in the envelope was only the fields that are writeable in that endpoint request?
This Create Payment request
{
"amount_money": {
"currency": "USD",
"amount": 9500
},
"idempotency_key": "f3c1c71f-6703-465d-8219-387912020c14",
"source_id": "cnon:card-nonce-ok",
"autocomplete": false,
"order_id": "b59cmFTMltVTycU3bj5PsIiouaB",
"customer_id": "VT5X2WXW1MRTXE4SQ5HFBH4ZGC"
}
Becomes this Create Payment request
{
"idempotency_key": "f3c1c71f-6703-465d-8219-387912020c14",
"payment" : {
"amount_money": {
"currency": "USD",
"amount": 9500
},
"source_id": "cnon:card-nonce-ok",
"autocomplete": false,
"order_id": "b59cmFTMltVTycU3bj5PsIiouaB",
"customer_id": "VT5X2WXW1MRTXE4SQ5HFBH4ZGC"
}
}
I know the difference isn’t that big, but its kind of a hybrid between the two patterns. But if you can imagine, its more like we’re masking certain fields in the shared model to only have the fields that are relevant to that particular request being exposed.
Part of the reasoning here being that fields that are relevant in the Create might not be relevant in the Update. This is especially the case if the field is set in a Create, but after that is immutable (basically a write-once field).
That is a little harder to express in a validation on shared models, but if you’re not entirely sharing the model between the Create and Update, you can sort of sidestep that issue.
Your feedback is really helpful and I will certainly be sharing it with our API design team