Skip to content

Instantly share code, notes, and snippets.

@Steven24K
Created October 15, 2021 12:09
Show Gist options
  • Save Steven24K/0f21559f8b7e9fccc0dfc5af3fa27933 to your computer and use it in GitHub Desktop.
Save Steven24K/0f21559f8b7e9fccc0dfc5af3fa27933 to your computer and use it in GitHub Desktop.
A small ready to copy Python Flask api. I use this when I need a simple proxy for my fontend app to consume.
from flask import Flask, jsonify, request
from flask_cors import CORS
import requests
# RUn the app by running flask run -p 3000 you can change the port number if have allready something running on port 3000
app = Flask(__name__)
# Allow CORS on every request
CORS(app)
@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def index(path):
return "Little api"
@app.route('/api/v1/my-method')
def get_some_data():
url = "https://api.sampleapis.com/beers/ale"
payload={}
headers = {}
response = requests.request("GET", url, headers=headers, data=payload)
return jsonify(response.json())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment