Submitting a large amount of info to a post

24 views
Skip to first unread message

jcor...@etsos.co.uk

unread,
Jun 17, 2015, 11:07:00 AM6/17/15
to taffy...@googlegroups.com
Hi,

I'm new to using Taffy (and REST) but so far I'm loving how easy it is to write, I've got part of my API written and it was extremely easy to do. However now I'm stuck. I'm probably being a bit thick but I've read the docs front to back and whilst I have seen mention of deserialisers I'm not sure how it applies to me

The API I'm writing is to allow an end client to submit orders to us for Anti-Money Laundering checks, so they first create the case which I return a reference to and then submit the details of the order.

I know how to do this in XML and have written an XSD for a similar service in SOAP but I'm completely stumped on how to do this in Taffy.

It's basic structure (in XML) is

<?xml version="1.0" encoding="UTF-8"?>
<AMLOrder>
    <ClientConfirmation></ClientConfirmation>
    <ClientRisk></ClientRisk>
    <Client>
        <Title></Title>
        <FirstName></FirstName>
        <MiddleName></MiddleName>
        <LastName></LastName>
        <DateOfBirth></DateOfBirth>
        <DrivingLicence></DrivingLicence>
        <NationalInsuranceNum></NationalInsuranceNum>
        <Passport>
            <CountryCode></CountryCode>
            <ExpiryDate></ExpiryDate>
            <PassportNumber>
                <FirstBlock></FirstBlock>
                <SecondBlock></SecondBlock>
                <ThirdBlock></ThirdBlock>
                <ForthBlock></ForthBlock>
                <FifthBlock></FifthBlock>
            </PassportNumber>
        </Passport>
        <Addresses>
            <Address>
                <Organisation></Organisation>
                <Premise></Premise>
                <SubPremise></SubPremise>
                <Street></Street>
                <DependentStreet></DependentStreet>
                <DependentLocality></DependentLocality>
                <DoubleDependentLocality></DoubleDependentLocality>
                <Town></Town>
                <Postcode></Postcode>
                <Region></Region>
                <Country></Country>
                <TimeAtAddress></TimeAtAddress>
                <CurrentAddress></CurrentAddress>                
            </Address>
        </Addresses>
    </Client>
</AMLOrder>

There are various enums and arrays in there (especially for the Addresses), how do I get that into my post function for the resource orderAML/{ourRef} ?

Thanks for any help in advance.

Joanne




Adam Tuttle

unread,
Jun 17, 2015, 11:36:08 AM6/17/15
to taffy...@googlegroups.com
Hi Joanne,

Unfortunately CF doesn't give us many tools to deal with XML, and the tools we do have (xmlparse, etc) are nowhere near as friendly as the tools for JSON.

It sounds like you will need an XML deserializer. You might look into XMLToAnything - it's possible that could do what you need.

As far as Taffy is concerned, when a POST is received for these details, it'll send the input XML (string) to your deserializer cfc, and whatever is returned from your deserializer is what will be passed as the argument collection to your resource POST method.

So, for example, your POST method might have arguments named ClientConfirmation, ClientRisk, and Client. Getting from the XML string to a structure that contains those keys in a format that you want to use them is up to you to implement; and that's what goes into the deserializer.

Think of this next bit not as JSON, but as CFML objects. This is what you want your XML to be translated to:

{ ClientConfirmation: "", ClientRisk: "", Client: { Title: "", FirstName: "", ... } }

BUT be sure that your deserializer is generic enough to handle ANY xml that you want to throw at it (don't JUST implement a deserializer for the input you expect for this resource); your resources should then look for what they need in input that they receive.

HTH
-Adam

--
You received this message because you are subscribed to the Google Groups "Taffy Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to taffy-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jcor...@etsos.co.uk

unread,
Jun 17, 2015, 11:44:41 AM6/17/15
to taffy...@googlegroups.com
Thanks Adam for coming back to me, I don't think I made myself clear.

I need it to be submitted as JSON as that's what the client I'm doing this as a piece of integration work for requires - I'm just struggling to understand how I would do that and moreover provide details to the consumers of the service on what to submit

Does that make any sense?

Joanne

Adam Tuttle

unread,
Jun 17, 2015, 11:57:53 AM6/17/15
to taffy...@googlegroups.com
Ah well that's much easier!

"Order": {
"ClientConfirmation": "",
"ClientRisk": "",
"Client": {
"Title": "",
"FirstName": "",
"MiddleName": "",
"LastName": "",
"DateOfBirth": "",
"DrivingLicence": "",
"NationalInsuranceNum": "",
"Passport": {
"CountryCode": "",
"ExpiryDate": "",
"PassportNumber": {
"FirstBlock": "",
"SecondBlock": "",
"ThirdBlock": "",
"ForthBlock": "",
"FifthBlock": ""
}
},
"Addresses": [
{
"Organisation": "",
"Premise": "",
"SubPremise": "",
"Street": "",
"DependentStreet": "",
"DependentLocality": "",
"DoubleDependentLocality": "",
"Town": "",
"Postcode": "",
"Region": "",
"Country": "",
"TimeAtAddress": "",
"CurrentAddress": ""
},
{...}
]
}
}
}

For the Addresses collection, it's a JSON array. The {...} signifies that they can add as many address objects to the array as they like.

Your taffy resource method would have an argument named "order" that would receive everything inside the "order" object... or you could exclude the "order" bit from the json (so start with ClientConfirmation) and have arguments named ClientConfirmation, ClientRisk, and Client. All of the sub-fields of Client would be contained within the value sent to Client... Client would be passed something that looks like: { title: "", ... }

Make sense?

jcor...@etsos.co.uk

unread,
Jun 17, 2015, 12:05:56 PM6/17/15
to taffy...@googlegroups.com
Ahhh OK, it is how I thought, one last piece of the puzzle to get it straight in my head, Do I use CFML structs for each of the json struct objects? For the array of Address objects, is it just an array of structs?

Thank you so much for the help

Regards

Joanne

Adam Tuttle

unread,
Jun 17, 2015, 12:08:52 PM6/17/15
to taffy...@googlegroups.com
Yup!

jcor...@etsos.co.uk

unread,
Jun 17, 2015, 12:40:20 PM6/17/15
to taffy...@googlegroups.com
Brilliant, thank you - I just couldn't get my head around it, combination of being ill with a temperature and fuzzy head and overthinking it, I thought it was a lot more difficult than I was expecting it to be

Joanne
Reply all
Reply to author
Forward
0 new messages