Advertisement
killerbrenden

REST API

Dec 6th, 2020
627
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 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, command):
  15.         args = command.split("_")
  16.         cmd = args[0]
  17.         args.remove(cmd)
  18.         commands[cmd] = ", ".join(args)
  19.         return {"data": "Updated commands"}
  20.  
  21. api.add_resource(GetCommands, "/getCommands")
  22. api.add_resource(PostCommand, "/postCommand/<string:command>")
  23.  
  24. if __name__ == "__main__":
  25.     app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement