i have made web2py web application. api endpoints exposed follows.
"/comments[comments]" "/comments/id/{comments.id}" "/comments/id/{comments.id}/:field" "/comments/user-id/{comments.user_id}" "/comments/user-id/{comments.user_id}/:field" "/comments/date-commented/{comments.date_commented.year}" "/comments/date-commented/{comments.date_commented.year}/:field" "/comments/date-commented/{comments.date_commented.year}/{comments.date_commented.month}" "/comments/date-commented/{comments.date_commented.year}/{comments.date_commented.month}/:field" "/comments/date-commented/{comments.date_commented.year}/{comments.date_commented.month}/{comments.date_commented.day}" "/comments/date-commented/{comments.date_commented.year}/{comments.date_commented.month}/{comments.date_commented.day}/:field" "/comments/date-commented/{comments.date_commented.year}/{comments.date_commented.month}/{comments.date_commented.day}/{comments.date_commented.hour}" "/comments/date-commented/{comments.date_commented.year}/{comments.date_commented.month}/{comments.date_commented.day}/{comments.date_commented.hour}/:field" "/comments/date-commented/{comments.date_commented.year}/{comments.date_commented.month}/{comments.date_commented.day}/{comments.date_commented.hour}/{comments.date_commented.minute}" "/comments/date-commented/{comments.date_commented.year}/{comments.date_commented.month}/{comments.date_commented.day}/{comments.date_commented.hour}/{comments.date_commented.minute}/:field" "/comments/date-commented/{comments.date_commented.year}/{comments.date_commented.month}/{comments.date_commented.day}/{comments.date_commented.hour}/{comments.date_commented.minute}/{comments.date_commented.second}" "/comments/date-commented/{comments.date_commented.year}/{comments.date_commented.month}/{comments.date_commented.day}/{comments.date_commented.hour}/{comments.date_commented.minute}/{comments.date_commented.second}/:field" "/comments/complaint-id/{comments.complaint_id}" "/comments/complaint-id/{comments.complaint_id}/:field"
the comments model follows models/db.py
db.define_table( 'comments', field('user_id', db.auth_user), field('comment_made', 'string', length=2048), field('date_commented', 'datetime', default=datetime.now), field('complaint_id', db.complaints), field('detailed_status', 'string', length=2048), )
i have been successful in retriving single comment via following request
localhost:8000/api/comments/id/1.json
now wish retrieve comments. not able figure out how use /comments[comments] retrieve comments.? have tried
localhost:8000/api/comments.json
but gives output "invalid path"
i have realized requests such http://localhost:8000/api/comments/complaint-id/1.json
give "invalid path" output. please help.
edit: controllers/default.py
@request.restful() def api(): response.view='generic.' + request.extension def get(*args,**kargs): patterns='auto' parser = db.parse_as_rest(patterns,args,kargs) if parser.status == 200: return dict(content=parser.response) else: raise http(parser.status,parser.error) def post(*args,**kargs): return dict() return locals()
routes.py in main web2py folder change default application:
routers = dict( base = dict( default_application='grs', ) )
another observation:
i added endpoint below:
def comm(): """" comments api substitute""" rows=db().select(db.comments.all) ## line shows error # rows = db(db.comments.id > 0).select() #rows=[[5,6],[3,4],[1,2]] #for row in rows: # print row.id return dict(message=rows)
even not able retrieve comments "/comm.json". gives web2py error ticket says "need more 1 value unpack" on line "rows=db.select(db.comments.all)". above invalid path , error related in someway?
Comments
Post a Comment