Newbie question - passing fields

51 views
Skip to first unread message

Jurgen Puype

unread,
Nov 8, 2016, 7:02:10 AM11/8/16
to Taffy Users
Hi all,

I just started using Taffy for an new project as mine, and I must say that I'm really impressed with it.

However I was wondering if there is a way to send request arguments in the body of the http call instead of the url?
I have some API-endpoints that take a lot of fields, some optional, so that url would become kind of long and in my personal opinion confusing.

Sincerely,
Jurgen 

Adam Tuttle

unread,
Nov 8, 2016, 9:35:04 AM11/8/16
to Taffy Users
Yes!

Just as Taffy supports multiple output formats through the use of Serializers, you may use Deserializers to parse post-body data (traditionally only used for POST and PUT requests, though I think Taffy will parse it no matter what verb is used, if you send one).

By default, it is assumed you want to accept JSON input data. If you want to accept anything else, you'll need to write a custom deserializer.

If you send a request like so (line 2 is the body text):

POST /foo/bar
{ "widgets": 4 }

Then the CFC with taffy:uri="/foo/bar" will get its POST method called, with the following argumentCollection: { widgets: 4 }

Sending an object as the body will map the keys in the object to the method arguments. So:

function post( widgets ){ ... }

will be called like this: post( argumentCollection: { widgets: 4 } );

If you want, you can post an array instead of an object as the request body:

POST /foo/bar
[ "a", "b", 42 ]

And the default Deserializer that ships with taffy will send this to your resources as _body (note: still deserialized, not as a string):

post( argumentCollection: { _body: [ "a", "b", 42 ] } );


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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages