aboutsummaryrefslogtreecommitdiff
path: root/test_api/test_api.py
blob: cce55f47fc72398dcfbd0af23b0633a788239785 (plain)
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
from bottle import get, post, run, HTTPError

@get("/")
def get_root():
    return {"status": "OK"}

@get("/long")
def get_long():
    return {"data": [
        {"name": "apple", "calories": 5},
        {"name": "orange", "calories": 120},
        {"name": "pear", "calories": 45},
    ]}

@post("/")
def post_root():
    return {"status": "SUCCESS"}

@get("/errors/404")
def error_404():
    raise HTTPError(404, body={"error": "no exist"})

@get("/errors/500")
def error_500():
    raise HTTPError(500, body={"error": "server error"})

run(host="localhost", port=8080)