Created
October 23, 2017 17:24
-
-
Save JacopoMangiavacchi/c6e9b5ab099902e891af79ead389c210 to your computer and use it in GitHub Desktop.
Python - Sanic Rest Test : <- Post <- Request <- Get
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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