Skip to content

Instantly share code, notes, and snippets.

@Taormina
Created September 2, 2014 01:08
Show Gist options
  • Save Taormina/483841ef835c14c13cd5 to your computer and use it in GitHub Desktop.
Save Taormina/483841ef835c14c13cd5 to your computer and use it in GitHub Desktop.
Placebo - A Dummy Endpoint Generator
from flask import Flask, request, abort
app = Flask(__name__)
responseMap = {}
@app.route('/reserved/<path:endpoint>', methods=['POST', 'PUT'])
def add_endpoint(endpoint):
responseMap[endpoint] = request.data
return "HTTP 200 - Endpoint {0} added!\nResponse: {1}\n".format(endpoint, responseMap[endpoint])
@app.route('/reserved/<path:endpoint>', methods=['DELETE'])
def del_endpoint(endpoint):
del responseMap[endpoint]
return "HTTP 200 - Endpoint {0} deleted!\n".format(endpoint)
@app.route('/reserved/<path:endpoint>', methods=['GET'])
def get_endpoint(endpoint):
return app.route('/dummy/{0}'.format(endpoint))
@app.route('/dummy/<path:path>')
def catch_all(path):
if '..' in path or path.startswith('/') or path not in responseMap.keys():
abort(404)
print 'HTTP 200 - {0} endpoint hit!\n'.format(path)
return responseMap[path]
@app.errorhandler(404)
def error404(e):
return "HTTP 404 - Sorry\n"
if __name__ == '__main__':
app.run(debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment