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:
chrome network log:
Request URL:
Request Method:
POST
Status Code:
200 OK
- Request Headersview source
Accept:
application/json, text/plain, */*
Accept-Encoding:
gzip,deflate,sdch
Accept-Language:
es,en-US;q=0.8,en;q=0.6
Connection:
keep-alive
Content-Length:
46
Content-Type:
application/json;charset=UTF-8
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
Host:
Origin:
Referer:
User-Agent:
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36
- Request Payloadview source
{id:0, first_name:John, last_name:Doe}
- first_name: "John"
- id: 0
- last_name: "Doe"
- Response Headersview source
Cache-Control:
no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection:
keep-alive
Content-Length:
4
Content-Type:
text/html; charset=utf-8
Date:
Sun, 21 Jul 2013 17:38:41 GMT
Expires:
Sun, 21 Jul 2013 17:38:41 GMT
Pragma:
no-cache
Server:
Rocket 1.2.6 Python/2.7.5
Set-Cookie:
session_id_angularjs=127.0.0.1-9453b1e9-444d-4fe4-8110-9d956bfda316; Path=/
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