def post(self): # check xsrf cookie self.check_xsrf_cookie() # get data from request body data = tornado.escape.json_decode(self.request.body) if data["protocol"] == "rest": method, url_path = data["id"].split("-") method_file = ResourceMethod(self.api_dir, url_path, method) elif data["protocol"] == "rpc": method_file = RPCMethod( os.path.join(self.api_dir, RPCHandler.PATH), data["id"]) # load description method_file.load_description() # set todo value = " %s" % data["value"].strip() todo = "%s%s" % ("[x]" if data["checked"] else "[ ]", value) method_file.description = re.sub( r"\[( |x)\]%s" % re.escape(value), todo, method_file.description) # save description method_file.save_description() self.set_header("Content-Type", "application/json") self.write("OK")
def post(self): # check xsrf cookie self.check_xsrf_cookie() # get data from request body data = tornado.escape.json_decode(self.request.body) # save resource for response in data["responses"]: # save resource method_file = ResourceMethod( self.api_dir, data["url_path"], data["method"]) method_file.description = data["description"] method_file.add_response( response["status_code"], response["format"], response["body"], response["headers"]) method_file.save() # add resource to category self.api_data.save_category( method_file.id, data["category"]) self.set_flash_message( "success", "Resource '%s' has been successfully created." % data["url_path"]) self.set_header("Content-Type", "application/json") self.write("OK")