Answer the question
In order to leave comments, you need to log in
Is it correct to make API JSON Body with optional keys?
Hello,
The question is to understand whether it is right to do such an API design or do I need to use other principles? (If others, which ones?)
I send an API call with a JSON Body in which I have the following keys:
{
"order_id"
"customer_id"
"patient_age"
"referral_reasons"
"patient_gender"
}
"order_id"
"customer_id"
Answer the question
In order to leave comments, you need to log in
In general, both options are appropriate.
But. It is often more convenient for the front to have the back pass all the fields, and empty ones would be marked as null.
It depends on the implementation at the front. In general, as agreed.
I am for the minimum option so that unnecessary fields are not transferred, but only required ones.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question