XML as request body

65 views
Skip to first unread message

Russ

unread,
Dec 19, 2013, 7:01:08 PM12/19/13
to taffy...@googlegroups.com
I'm new to Taffy, and new to writing api's in general. I have things wired up to respond in both json and xml formats. What I'm needing help doing/understanding is does that mean that incoming requests can be in xml or json format as well?

So a quick and dirty example:
Contacts Resource:
put:
{
id: 1,
name: "bob",
phone: "555-555-5555"
}

put:
<xml>
<id>1</id>
<name>bob</name
<phone>555-555-5555</phone>
</xml>

As I have things setup to respond in those to formats, does it also mean I can accept requests in those two formats as well? If not what do I need to do to be able to accept XML requests? Any examples?

Thanks! Taffy is great!

Adam Tuttle

unread,
Dec 19, 2013, 10:50:36 PM12/19/13
to taffy...@googlegroups.com
Hi Russ,

Glad you like Taffy! Unfortunately I don't have much in the way of good news as responses to your questions.

As of right now, Taffy is capable of sending data in any format imaginable (via custom representation classes, as it sounds like you've figured out) - but can only accept input either as a JSON payload, from URL parameters (/foo.json?foo=bar), or as a form-encoded body (as crazy as it sounds, this is just query-string formatting, without the leading question mark, and in the request body instead of the URL. Crazy, but that's the standard for form posts).

One of the early feature requests was for input deserializers (the inverse of custom representation classes) -- I believe we have Barney Boisvert to thank for this idea. It's something I would love to do but it just hasn't made it to the top of the priority list yet. (Pull requests encouraged! Hit me up if you want to talk specifics)

Another, easier to implement ER that would enable you to get there is the idea of non-recognized request bodies being available as a "_body" argument to the resource (prefixed to avoid potential conflicts with resource arguments defined by developers). Basically, if XML or some other unrecognized format is received, instead of throwing an exception the framework would make the raw request body available to the resource methods (and onTaffyRequest) as _body and you could then deserialize it yourself. 

If you were to go this latter route, I would recommend generalizing the solution in onTaffyRequest, of course: adding keys to the requestArguments argument will make them available in your resources as if they were sent directly from the consumer.

Again, pull requests are always welcome! :D

Hope that helps clarify the current state of things!

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/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages