Dirk posted this on web2pyslices...

To PUT (=update) something, you need to call:

curl -i -H "Accept: application/json" -X PUT --user user:pass -d
"f_entry=something newest"
http://127.0.0.1:8000/RT/default/api/entries/1.json

with id=1 being an existing entry.

So of course, PUT works as update... the 1.json refers to an existing
record...

If you want to create a new record you need to use POST, I think...


On Fri, Aug 10, 2012 at 3:21 PM, Tito Garrido <titogarr...@gmail.com> wrote:

> Version 1.99.4 (2011-12-14 14:46:14) stableRunning on Apache/2.2.17
> (Unix) mod_wsgi/3.3 Python/2.7.3
>
> On Fri, Aug 10, 2012 at 11:00 AM, Massimo Di Pierro <
> massimo.dipie...@gmail.com> wrote:
>
>> Which web2py version?
>>
>>
>> On Friday, 10 August 2012 08:39:40 UTC-5, Tito Garrido wrote:
>>
>>> Same error using locals()
>>>
>>> :(
>>>
>>> On Thu, Aug 9, 2012 at 5:23 PM, Bruno Rocha <rocha...@gmail.com> wrote:
>>>
>>>> try to replace  return dict(GET=GET, POST=POST, PUT=PUT, DELETE=DELETE)
>>>> with return locals()
>>>>
>>>> I dont know, but maybe its the problem
>>>>
>>>> On Wed, Aug 8, 2012 at 10:49 PM, Tito Garrido <titog...@gmail.com>wrote:
>>>>
>>>>> Hi folks,
>>>>>
>>>>> *I have a simple table:*
>>>>>
>>>>> *db.define_table('estadio',
>>>>>     Field('cod_estadio','id'),
>>>>>     Field('nome_estadio'),
>>>>>     Field('cidade'),migrate=False) *
>>>>>
>>>>> *A simple entry:*
>>>>>
>>>>> *estadio.cod_estadio**estadio.nome_estadio* *estadio.cidade**1**A
>>>>> Definir**A Definir*
>>>>> and using Bruno's example in web2pyslice:
>>>>>
>>>>>
>>>>>    1. @request.restful()
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>    2. def api():
>>>>>    3.     response.view = 'generic.'+request.extension
>>>>>    4.     def GET(*args,**vars):
>>>>>    5.         patterns = 'auto'
>>>>>    6.         parser = db.parse_as_rest(patterns,args**,vars)
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>    7.         if parser.status == 200:
>>>>>    8.             return dict(content=parser.response)
>>>>>    9.         else:
>>>>>    10.             raise HTTP(parser.status,parser.erro**r)
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>    11.     def POST(table_name,**vars):
>>>>>    12.         return db[table_name].validate_and_**insert(**vars)
>>>>>    13.     def PUT(table_name,record_id,**var**s):
>>>>>    14.         return db(db[table_name]._id==record_**id).update(**vars)
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>    15.     def DELETE(table_name,record_id):
>>>>>    16.         return db(db[table_name]._id==record_**id).delete()
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>    17.     return dict(GET=GET, POST=POST, PUT=PUT, DELETE=DELETE)
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> *but when I try to:*
>>>>> *
>>>>> curl -i -H "Accept: application/json" -X PUT -d "nome_estadio='teste"
>>>>> http://127.0.0.1:8080/ws/default/api/estadio/cod-estadio/1.json*
>>>>>
>>>>> *it returns:*
>>>>>
>>>>> HTTP/1.1 400 BAD REQUEST
>>>>> Server: nginx
>>>>> Date: Thu, 09 Aug 2012 01:41:44 GMT
>>>>> Content-Type: text/html; charset=UTF-8
>>>>> Connection: keep-alive
>>>>> Set-Cookie: 
>>>>> session_id_ws=xxxxxxxxxx-**65e0b712-7d93-4b21-a553-**d06ce06af2a2;
>>>>> Path=/
>>>>> Content-Length: 540
>>>>>
>>>>> invalid arguments<!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx**
>>>>> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx**xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx**
>>>>> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx**xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx**
>>>>> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx**xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx**
>>>>> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx**xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx**
>>>>> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx**xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx**
>>>>> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx**xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx**
>>>>> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx**xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx**
>>>>> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx**xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx**xx
>>>>> //-->
>>>>>
>>>>> *What am I missing here?
>>>>>
>>>>> Thanks in advance!*
>>>>>
>>>>>
>>>>> --
>>>>>
>>>>> Linux User #387870
>>>>> .........____
>>>>> .... _/_õ|__|
>>>>> ..º[ .-.___.-._| . . . .
>>>>> .__( o)__( o).:_______
>>>>>
>>>>> --
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>  --
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>> --
>>>
>>> Linux User #387870
>>> .........____
>>> .... _/_õ|__|
>>> ..º[ .-.___.-._| . . . .
>>> .__( o)__( o).:_______
>>>
>>  --
>>
>>
>>
>>
>
>
>
> --
>
> Linux User #387870
> .........____
> .... _/_õ|__|
> ..º[ .-.___.-._| . . . .
> .__( o)__( o).:_______
>
> --
>
>
>
>

-- 



Reply via email to