hi Jeremy, 
in the histories controller, I could find no example to nicely obtain the PUT 
and POST content  payload. Am I missing it?
So I think a bad answer to my question is the following code.  But I really 
don't like my _get_payload() hack reaching into the trans.environ object.   
Is there a better way to do this?
Thanks,
Ted


for the following curl  CRUD commands
curl -i -X POST -H 'Content-Type: application/json' -d '{"la": "di da" }' 
http://localhost:8081/api/assets/
curl -i -X GET -H 'Content-Type: application/json' -d '{"la": "di da" }' 
http://localhost:8081/api/assets/
curl -i -X GET -H 'Content-Type: application/json' -d '{"la": "di da" }' 
http://localhost:8081/api/assets/2
curl -i -X PUT -H 'Content-Type: application/json' -d '{"la": "di da" }' 
http://localhost:8081/api/assets/3
curl -i -X DELETE -H 'Content-Type: application/json' -d '{"la": "di da" }' 
http://localhost:8081/api/assets/4


in buildapp.py   // I also don't like the fact that it needs five separate 
calls. this is the sort of design pattern that should be very easy.

    webapp.mapper.connect("/api/assets/", controller="medbook", 
action="assets_create", conditions=dict(method=["POST"]))
    webapp.mapper.connect("/api/assets/", controller="medbook", 
action="assets_read", conditions=dict(method=["GET"]))
    webapp.mapper.connect("/api/assets/*url", controller="medbook", 
action="assets_read", conditions=dict(method=["GET"]))
    webapp.mapper.connect("/api/assets/*url", controller="medbook", 
action="assets_update", conditions=dict(method=["PUT"]))
    webapp.mapper.connect("/api/assets/*url", controller="medbook", 
action="assets_delete", conditions=dict(method=["DELETE"]))

in the assets controller file, something like

    def _get_payload(self, trans):
        " hack to return the payload content from a POST or a PUYT"
        try:
            length= int(trans.environ.get('CONTENT_LENGTH', '0'))
            if length!=0:
                return 
from_json_string(trans.environ['wsgi.input'].read(length))

        except ValueError:
            return None

    @web.json
    def assets_create( self, trans, **kwd ):
        doc  = "asset_create POST /api/assets:"
        return doc + to_json_string(self._get_payload(trans))

    @web.json
    def assets_read( self, trans, url="", **kwd ):
        doc  = "asset_read POST /api/assets:"
        return doc + url

    @web.json
    def assets_update( self, trans, url, **kwd ):
        doc  = "asset_update PUT /api/assets:"
        return doc + url + to_json_string(self._get_payload(trans))

    @web.json
    def assets_delete( self, trans, url, **kwd ):
        doc  = "asset_update DELETE /api/assets"
        return doc + url





On Sep 14, 2013, at 11:04 AM, Jeremy Goecks <jeremy.goe...@emory.edu> wrote:

> Take a look at the histories controller (histories.py) for an example + 
> documentation on how Galaxy realizes a RESTful interface. In short, you'll 
> want to implement different methods for create, read, update, and delete. 
> Kwds are miscellaneous parameters included in a request that are not 
> explicitly specified in a method signature.
> 
> Good luck,
> J.
> 
> On Sep 13, 2013, at 7:52 PM, Ted Goldstein, Ph.D. wrote:
> 
>> I've been knocking my head over this all afternoon and I was hoping to buy a 
>> vowel, use a lifeline, whatever.
>> 
>> I'm trying to use the Ember JS  framework (which is very nice) for some 
>> extensions.  It relies heavily on a REST model using the same method with 
>> all of the HTTP forms including 
>> 
>> Action       HTTP Verb       URL
>> Find GET     /people/123
>> Find All     GET     /people
>> Update       PUT     /people/123  (with the HTTP payload packed with the 
>> JSON content)
>> Create       POST    /people
>> Delete       DELETE  /people/123
>> 
>> How can I make an API function that responds to all five forms and what 
>> should be in buildapp.py?
>> 
>> All of the code in Galaxy currently uses the kwd (keyword) parameter. But 
>> there are no keywords here.
>> 
>> Confused,
>> Ted
>> 
>> 
>> ___________________________________________________________
>> Please keep all replies on the list by using "reply all"
>> in your mail client.  To manage your subscriptions to this
>> and other Galaxy lists, please use the interface at:
>> http://lists.bx.psu.edu/
>> 
>> To search Galaxy mailing lists use the unified search at:
>> http://galaxyproject.org/search/mailinglists/
> 


___________________________________________________________
Please keep all replies on the list by using "reply all"
in your mail client.  To manage your subscriptions to this
and other Galaxy lists, please use the interface at:
  http://lists.bx.psu.edu/

To search Galaxy mailing lists use the unified search at:
  http://galaxyproject.org/search/mailinglists/

Reply via email to