killerbrenden

REST API

Dec 6th, 2020 (edited)
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. from flask import Flask
  2. from flask_restful import Api, Resource
  3.  
  4. app = Flask(__name__)
  5. api = Api(app)
  6.  
  7. commands = {}
  8.  
  9. class GetCommands(Resource):
  10.     def get(self):
  11.         return commands
  12.  
  13. class PostCommand(Resource):
  14.     def post(self, cmd):
  15.         args = cmd.split("_")
  16.         c = args[0]
  17.         args.remove(c)
  18.         commands[c] = ", ".join(args)
  19.         return {"Server": "Command updated"}
  20.      
  21. class DeleteCommand(Resource):
  22.     def delete(self, cmd):
  23.       commands.pop(cmd, None)
  24.       return {"Server": "Command deleted"}
  25.      
  26.  
  27. api.add_resource(GetCommands, "/getCommands")
  28. api.add_resource(PostCommand, "/postCommand/<string:cmd>")
  29. api.add_resource(DeleteCommand, "/deleteCommand/<string:cmd>")
  30.  
  31. if __name__ == "__main__":
  32.     app.run(debug=False)
Add Comment
Please, Sign In to add comment