Skip to content

Instantly share code, notes, and snippets.

@JacopoMangiavacchi
Created October 23, 2017 17:24
Show Gist options
  • Save JacopoMangiavacchi/c6e9b5ab099902e891af79ead389c210 to your computer and use it in GitHub Desktop.
Save JacopoMangiavacchi/c6e9b5ab099902e891af79ead389c210 to your computer and use it in GitHub Desktop.
Python - Sanic Rest Test : <- Post <- Request <- Get
from sanic import Sanic, response
import requests
app = Sanic(__name__)
@app.route('/language', methods=['GET'])
async def get_language(request):
return response.json({'language': 'Python'})
@app.route('/request', methods=['POST'])
async def get_language(req):
if not req.json or not 'url' in req.json:
return response.text(body= '', status=404)
url = req.json['url']
result = requests.get(url)
return response.json({'language': 'Python'})
app.run(host="0.0.0.0", port=8070, workers=4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment