Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to send selected Radio Button through JSON

I am creating a REST API and that will receive JSON data through POST. I’m creating the structure of the JSON now and was wondering what is considered best practice for how to send data signifying which Radio Button was selected on the sender’s side. I thought of 3 possible ways to do it, but I’m open to other options if there’s something better. Here are the 3 ways with UPS, FedEx and USPS being the sample options:

"UPS": false,
"FedEx": true,
"USPS": false

"ShippingCompany": 2 // 1 for UPS, 2 for FedEx, 3 for USPS

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

"ShippingCompany": "FedEx"

>Solution :

It depends on the use case and on who’s consuming the API.

Your first solution is the least favorable of these three, since you want to implement a radio button. This would be more of a checkbox situation.

Variant 2 and 3 are interchangeable, but I’d use 3, since it’s obvious what company you mean, instead of having to look up the meaning of the integers.

To go even further you could take a look at enums and their definition in openapi.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading