Hi Adam,
I'm nearing the completion of our API (100+ calls so far!) and one thing that I'm not happy with in my current code is how I handle adding multiple entities. Take the example of adding a contact with firstname & lastname:
<cfargument name="firstname" type="string" required="true" hint="First Name."/>
<cfargument name="lastname" type="string" required="true" hint="Last Name."/>
At the moment if I want to add more than one then I either have to make this call a heap of times (not good when I might want to use this to import 1000+ contacts) or I ask the user to separate the list of names with a delimiter (choosing wisely so this won't occur in the data itself).
Ideally what I'd like to do is to be able to accept single contacts like this:
{ "firstName":"John" , "lastName":"Doe" }
and multiple contacts like this:
[
{ "firstName":"John" , "lastName":"Doe" },
{ "firstName":"Anna" , "lastName":"Smith" },
{ "firstName":"Peter" , "lastName":"Jones" }
]
I might be missing something obvious but the only way I can currently see to do this is to require that the data is submitted as:
{
"contacts": [
{ "firstName":"John" , "lastName":"Doe" },
{ "firstName":"Anna" , "lastName":"Smith" },
{ "firstName":"Peter" , "lastName":"Jones" }
]
}
but that means I can't take advantage of taffy's dash for the argument hints which would be a bit of a blow as I have documented the crap out of them!
Any advice? Hoping it's just my relative lack of CF knowledge and too many late nights that are making me miss something obvious :)
Cheers,
Richard