-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
40 lines (31 loc) · 1.1 KB
/
main.py
File metadata and controls
40 lines (31 loc) · 1.1 KB
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
36
37
38
39
40
from fastapi import FastAPI, Query
import requests
app = FastAPI()
@app.get('/api/hello')
def hello_world():
'''
Endpoint que exibe uma mensagem incrível do mundo da programação!
'''
return {'Hello':'World'}
@app.get('/api/restaurantes/')
def get_restaurantes(restaurante: str = Query(None)):
'''
Endpoint para ver os cardápios dos restaurantes
'''
url = 'https://guilhermeonrails.github.io/api-restaurantes/restaurantes.json'
response = requests.get(url)
if response.status_code == 200:
dados_json = response.json()
if restaurante is None:
return{'Dados':dados_json}
dados_restaurante = []
for item in dados_json:
if item['Company'] == restaurante:
dados_restaurante.append({
"item": item['Item'],
"price": item['price'],
"description": item['description']
})
return {'Restaurante':restaurante, 'Cardapio':dados_restaurante}
else:
return {'Erro':f'{response.status_code}'} - {response.texto}