-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
35 lines (27 loc) · 773 Bytes
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import logging
import httpx
from os import abort
from flask import Flask, jsonify
from flask_pydantic_spec import FlaskPydanticSpec
app = Flask(__name__)
spec = FlaskPydanticSpec('flaskinho', title='Flaskinho API REST')
spec.register(app)
url = 'https://jsonplaceholder.typicode.com/todos/'
@app.get('/')
def get_five():
"""Returns first five JSONs from external API"""
r = httpx.get(url)
data = r.json()[0:5]
try:
return jsonify(data)
except httpx.HTTPStatusError:
abort(400, 'Bad request')
logging.basicConfig(
filename='record.log',
encoding='utf-8',
level=logging.DEBUG,
format=f'--------\n %(asctime)s %(levelname)s : %(message)s',
datefmt='%m/%d/%Y %H:%M:%S',
)
if __name__ == '__main__':
app.run()