Last active
July 19, 2018 00:26
-
-
Save vmesel/c1815fa7e0a8a280d5bbe88be992a1ac to your computer and use it in GitHub Desktop.
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 flask import Flask, request, jsonify | |
from flasgger import Swagger | |
app = Flask(__name__) | |
swagger = Swagger(app) | |
def find_contact(email, contact_list): | |
for item in contact_list: | |
if item['email'] == email: | |
return item | |
return {} | |
@app.route('/contact/') | |
def contact_list(): | |
""" | |
Example endpoint to return a list of contacts specified by email address. | |
--- | |
parameters: | |
- name: email | |
in: query | |
type: string | |
required: false | |
- name: key | |
in: query | |
type: string | |
default: HAHA | |
required: true | |
responses: | |
200: | |
description: A list of contacts (can be filtered by email) | |
schema: | |
$ref: '$/def' | |
""" | |
email = request.args.get('email') | |
api_key = request.args.get('key') | |
if api_key != "HAHA": | |
return jsonify({"error":"Bad request"}), 400 | |
contacts = {"contacts": [ | |
{'nome':'Paula', 'email': 'contato@paula.com'}, | |
{'nome':'Vinicius', 'email': 'contato@vinicius.com'} | |
]} | |
if email == None: | |
return jsonify(contacts), 200 | |
return jsonify({"contacts": find_contact(email, contacts["contacts"])}), 200 | |
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