Greetings everyone,
I've been using request.restful
to provide an restful interface to my angularjs app,
i tried to post data from the angularjs app and it works, it sends the data 
but in the POST method i've got an empty dictionary, here is my code and 
some data logs:

default controller
@request.restful()
def api():
    response.view = 'generic.json'
    def GET(table_name, id=None):
        if table_name in db:
            table = db[table_name]
            if id == None:
                query = (table.id > 0)
            else:
                try:
                    id = int(id or 0)
                except:
                    id = 0
                query = (table.id == id)
            return {table_name : db(query).select()}
    def POST(table_name, **vars):
        print(vars)
    return locals()

angular code used to post data:
$http.post('http://127.0.0.1:8000/angularjs/default/api/person/', item).
success(function(data) {
    console.log('POST: '+ item.first_name +' Result: '+ data);
});

chrome network log:

>
>    1. Request URL:
>    http://127.0.0.1:8000/angularjs/default/api/person/
>    2. Request Method:
>    POST
>    3. Status Code:
>    200 OK
>    4. Request Headersview source
>       1. Accept:
>       application/json, text/plain, */*
>       2. Accept-Encoding:
>       gzip,deflate,sdch
>       3. Accept-Language:
>       es,en-US;q=0.8,en;q=0.6
>       4. Connection:
>       keep-alive
>       5. Content-Length:
>       46
>       6. Content-Type:
>       application/json;charset=UTF-8
>       7. Cookie:
>       csrftoken=hMi7rvIHaxAu09tX0H8c2SDqmwwgS7Ra; 
>       session_id_admin=127.0.0.1-9ef67e29-1352-4fef-a621-fcc0c3fa9182; 
>       session_id_angularjs=127.0.0.1-9453b1e9-444d-4fe4-8110-9d956bfda316
>       8. Host:
>       127.0.0.1:8000
>       9. Origin:
>       http://127.0.0.1:8000
>       10. Referer:
>       http://127.0.0.1:8000/angularjs/default/index
>       11. User-Agent:
>       Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like 
>       Gecko) Chrome/28.0.1500.72 Safari/537.36
>       5. Request Payloadview source
>    {id:0, first_name:John, last_name:Doe}
>    1. first_name: "John"
>       2. id: 0
>       3. last_name: "Doe"
>    6. Response Headersview source
>       1. Cache-Control:
>       no-store, no-cache, must-revalidate, post-check=0, pre-check=0
>       2. Connection:
>       keep-alive
>       3. Content-Length:
>       4
>       4. Content-Type:
>       text/html; charset=utf-8
>       5. Date:
>       Sun, 21 Jul 2013 17:38:41 GMT
>       6. Expires:
>       Sun, 21 Jul 2013 17:38:41 GMT
>       7. Pragma:
>       no-cache
>       8. Server:
>       Rocket 1.2.6 Python/2.7.5
>       9. Set-Cookie:
>       session_id_angularjs=127.0.0.1-9453b1e9-444d-4fe4-8110-9d956bfda316; 
>       Path=/
>       10. X-Powered-By:
>       web2py
>       
>
I made some tests using the "requests" module and it works, so for instance 
i think that the problem is within the way that angularjs sends the data.

Thanks in advance,

Franco

>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to