Dear friends:
I hope everyone on this group is fine and in a good health, following is a
snippet from a code of training REST project i am working on:
def POST(self):
task = json.loads(web.data())
if not task or not task['title']:
raise web.HTTPError('400 Bad Resource!', data=json.dumps({
'error': 'Bad Resource!'
}))
else:
new_task = {
'title': task['title'],
'description': task.get('description', ''),
'done': False
}
db.insert('tasks', **new_task)
#web.created()
raise web.Created(data=json.dumps({
'task': new_task
}))
the question is regarding the behavior web types (HTTPError, Created) when
using return vs raise.
when i use raise for example as in the red line i get the required result :
201 Created
Headers
Cache-Control: no-cache
Content-Type: application/json
Transfer-Encoding: chunked
Date: Thu, 10 Dec 2020 12:43:09 GMT
Server: localhost
{ "task": { "title": "Learn Webpy", "description": "", "done": false } }
but when i use return i get:
201 Created
Headers
Cache-Control: no-cache
Content-Type: application/json
Transfer-Encoding: chunked
Date: Thu, 10 Dec 2020 12:43:09 GMT
Server: localhost
201 created
i did not understand this behavior , same thing regarding the debate
previously discussed on the group regarding return web.seeother vs raise
web.seeother.
is this issue concerning webpy or else is it problem with my code, for give
am just an amateur and for give me if my language is not clear.
Thank you very much
--
You received this message because you are subscribed to the Google Groups
"web.py" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/webpy/fc06b32a-6c9d-4984-9f72-caed159b127en%40googlegroups.com.