Jason,
Yes, that’s pretty much the way.
Kevin
~ -----Original Message-----
~ From:
cfr...@googlegroups.com [mailto:
cfr...@googlegroups.com] On
~ Behalf Of phenotypical
~ Sent: Wednesday, April 15, 2009 9:01 PM
~ To: cfrest
~ Subject: Re: Consumer code?
~
~
~ Ah, just stumbled upon this blog post from Mike Nimer:
~
http://blog.mikenimer.com/index.cfm/2006/10/2/DOJOJSON-requests-in-
~ ColdFusion
~
~ And he shows how to get at the request body - note the last comment by
~ Dan Switzer to use this: toString(getHttpRequestData().content)
~
~ So this is one way to do it! :) -Jason
~
~
~
~
~
~ On Apr 15, 12:28 pm, phenotypical <
jason.b...@gmail.com> wrote:
~ > Forgive me for forwarding this thread back to the list, but I don't
~ > appear to have the option to reply (to older threads perhaps?),
~ though
~ > I think my question is related:
~ >
~ > I'm building a REST api on top of a Mach-II application using SES
~ > url's and have no problem with GET's and DELETE's and parsing the
~ > requested resource and any arguments out of the url.
~ >
~ > But I'm a little confused about PUT's and POST's. Specifically most
~ > REST documentation advises to just POST or PUT the xml package as the
~ > body, just Kevin does in appUtilities.cfc
~ onhttp://
groups.google.com/group/cfrest/files
~ >
~ > ...line 57, in the method apiPOST:
~ >
~ > <cfhttp url="#arguments.resourceURL#" method="POST" result="response"
~ > timeout="#variables.labitoolsAPITimeout#"
~ > username="#arguments.authUsername#"
~ > password="#arguments.authPassword#" throwonerror="false">
~ > <cfhttpparam type="BODY" value="#arguments.requestbody#">
~ > </cfhttp>
~ >
~ > ...but here's my question: I seem to only be able to pick something
~ up
~ > on the server side (i.e. in the Mach-II application) if on the
~ client,
~ > I set this cfhttpparam type="formfield". But I gather this is not
~ > considered RESTful?
~ >
~ > IOW, on the server side, in ColdFusion, how would you access the
~ value
~ > of that cfhttpparam of #arguments.requestbody#? It's not in the CGI
~ > scope. Obviously not in form or url scopes. Not sure where else to
~ > look?
~ >
~ > Thanks in advance for any thoughts and thanks for setting this forum
~ > up btw!
~ >
~ > -Jason
~ >
~ > ---------- Forwarded message ----------
~ > From: websolete <
websol...@gmail.com>
~ > Date: Jan 15, 12:41 am
~ > Subject: Consumer code?
~ > To: cfrest
~ >
~ > See inline below:
~ >
~ > On Jan 15, 2:05 am, Brian G <
brian-goo...@vfive.com> wrote:
~ >
~ > > On Jan 13, 11:15 pm, websolete <
websol...@gmail.com> wrote:
~ >
~ > > > I uploaded apiUtilities.cfc to the files section. This is most
~ likely
~ > > > the equivalent of your RestConsumer.cfc.
~ >
~ > > Thanks! I've taken a look (and emailed you offline about the PUT/
~ > > binary issue) and it helped me finalize the restconsumer.cfc I
~ > > started. I've also leveraged your conversion utilities already and
~ > > they're working nicely. Although I do see you try to convert XML
~ > > attributes into top level keys if there aren't conflicts. ;)
~ >
~ > Yeah, and when I saw the resulting inconsistent format between xml
~ > with attributes and 'simple' node only xml, with no way to resolve it
~ > short of complicating the simple xml to generify it with the
~ > attributed version (felt wrong), I dropped using attributes for these
~ > types of things. The work was done so the function remains just in
~ > case there's a use case.
~ >
~ > > > I believe that if you need to include 'form field' values which
~ are
~ > > > not explicitly defined as being required to be part of the
~ request
~ > > > body, and therefore implicitly beyond the scope of the target
~ api,
~ > > > that they should be sent as URL params and be part of the
~ resource
~ > > > URI, but thats of course up to the target api to define.
~ >
~ > > Is it incorrect, either practically or theoretically, to post name/
~ > > value pairs (e.g., standard POST of encoded data) to a resource? I
~ > > guess what I'm asking is if REST would say you MUST or SHOULD post
~ a
~ > > resource packet (properly formed XML, JSON, etc) or if posting the
~ > > name/value pairs is appropriate?
~ >
~ > A relevant paragraph from the wikipedia article on REST:
~ >
~ > "An important concept in REST is the existence of resources (sources
~ > of specific information), each of which is referenced with a global
~ > identifier (e.g., a URI in HTTP). In order to manipulate these
~ > resources, components of the network (clients and servers)
~ communicate
~ > via a standardized interface (e.g., HTTP) and exchange
~ representations
~ > of these resources (the actual documents conveying the information).
~ > For example, a resource which is a circle may accept and return a
~ > representation which specifies a center point and radius, formatted
~ in
~ > SVG, but may also accept and return a representation which specifies
~ > any three distinct points along the curve as a comma-separated list."
~ >
~ > Therefore, what you're doing is exchanging a 'representation' of the
~ > the intended resource; while you could convey the new state of the
~ > resource in form fields, xml and json as data exchange formats are
~ > vastly superior to multiple string or binary form fields since you
~ can
~ > encapsulate a lot of different and relevant data about the resource
~ in
~ > a 'single' packet. It also has to do with having a consistency in
~ the
~ > input/output into the api so that the GET response can match closely
~ > or exactly (if desired) the POST or PUT packet format, simplifying
~ the
~ > serialization/deserialization of request/responses.
~ >
~ > I'm not sure if there are explicit rules or guidelines in REST that
~ > prohibit the use of multiple form fields to convey representations,
~ > but it felt wrong to me and wrapping it all up in a data exchange
~ > format like xml/json just felt right. I won't say it was all
~ pleasant
~ > happy work to do it that way, but it all works seamlessly now that
~ the
~ > work is done and since I consume my own api in at least one other
~ app,
~ > I found that there was a lot of predictability in how to POST and PUT
~ > and what I should expect back from a GET. In hindsight, I'd do it
~ > this way again.
~ >
~ > > Your apiUtilities.cfc would suggest that you only ever submit a
~ > > resource as the content body (in apiPOST).
~ >
~ > Correct.
~ >
~ > > Brian
~