SHARE
TWEET

Untitled

a guest Jan 29th, 2020 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import falcon
  2. from waitress import serve
  3. from models import *
  4. from playhouse.shortcuts import model_to_dict
  5. import json
  6.  
  7.  
  8. class UserIdResource():
  9.      def on_get(self, req, resp, user_id):
  10.          try:
  11.              user = urozaev.get(urozaev.id == user_id)
  12.              resp.body = json.dumps(model_to_dict(user))
  13.          except urozaev.DoesNotExist:
  14.              resp.status = falcon.HTTP_404
  15.  
  16.  
  17. class UserResource():
  18.      def on_get(self, req, resp):
  19.          users = urozaev.select().order_by(urozaev.id)
  20.          resp.body = json.dumps([model_to_dict(u) for u in users])
  21.  
  22.  
  23. api = falcon.API()
  24.  
  25. users = UserResource()
  26. users_id = UserIdResource()
  27.  
  28. api.add_route('/users/', users)
  29. api.add_route('/users/{user_id}', users_id)
  30.  
  31. serve(api, host="127.0.0.1", port=8001)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top