---
# System prepended metadata

title: Vaja Flask API

---

# Vaja Flask API

V tej vaji ustvari naslednje "route":
Zgleduj se po /randOseba vaji.

1. /coinFlip
    Ta route vrne ali sliko glave ali grba kovanca.
    :::success
    Odgovor v obliki: 
    {"img" : "urlDoslikeGlave", "status": "head"} ali
    {"img" : "urlDoslikeGrba",  "status": "tails"}
    :::
    Head: https://i.postimg.cc/CBNJNfDJ/head.png
Tail: https://i.postimg.cc/zysdXN8w/tail.png
2. /randomQuote
    Ta route naj vrne naključen quote iz tvoje najljubše serije, od tvoje najljubše osebe... Vsaj 10 različnih quotov.
      :::success
    Recimo /randomQuote vrne naključen quote.
    Odgovor v obliki {"quote": "Sometimes you win, sometimes you learn."}
    :::
    
3. /randomNum/<min>/<max>
    Ta route vrne naključno število med min in max.
    
    **Za pozabljivce**
    
    ```python=
    @app.route("/route/<param1>/<param2>")
        def hello_world(param1, param2):
        print(param1, param2)
        return [param1, param2]
    ```
    
    :::success
    Recimo /randomNum/1/30: Pomeni, da generiramo naključno število med 1 in 30.
    Odgovor v obliki {"number": 22, "min" : 1, "max": 30 }
    :::
4. /randPassword/<length>
    Ta route vrne naključno geslo <length> dolgo.
    Geslo naj vsebuje številke, male, velike črke in posebne znake.
    Pomagaj si z: string.ascii_letters in string.punctuation
    https://www.geeksforgeeks.org/string-punctuation-in-python/
    https://docs.python.org/3/library/string.html
    :::success
    Recimo /randPassword/7: Pomeni, da generiramo 7 dolgo geslo.
    Odgovor v obliki {"password": "ABC12%&", "length" : 7 }
    :::
5. /randDice/<sides>/<numDices>
    Ta route vrne rezultat <sides> strane kocke, ki jo vržemo <numDices> x.
    Izpiši vse mete in rezultat metov.
    :::success
    Recimo /randDice/12/5: Pomeni, da 5x vržemo 12 strano kocko.
    Odgovor v obliki {"throws": [3,6,7,11,12], "sum" : 39 }
    :::
    
    
## **TESTI**
V ločeni python skripti(replu) zaženi svojo kodo, če se koda ne sesuje je vse OK!
**Ne pozabi zamenjati domene na svojo repl domeno.**
    
```python=
import requests

base_url = 'http://your_server_url'

def test_coin_flip():
    response = requests.get(f'{base_url}/coinFlip')
    data = response.json()
    print("Coin Flip Image:", data['img'])
    print("Coin Flip Status:", data['status'])

def test_random_quote():
    response = requests.get(f'{base_url}/randomQuote')
    data = response.json()
    print("Random Quote:", data['quote'])

def test_random_number():
    response = requests.get(f'{base_url}/randomNum/1/30')
    data = response.json()
    print("Random Number:", data['number'])
    print("Min Value:", data['min'])
    print("Max Value:", data['max'])

def test_random_password():
    response = requests.get(f'{base_url}/randPassword/7')
    data = response.json()
    print("Random Password:", data['password'])
    print("Password Length:", data['length'])

def test_random_dice():
    response = requests.get(f'{base_url}/randDice/12/5')
    data = response.json()
    print("Dice Throws:", data['throws'])
    print("Sum of Throws:", data['sum'])

# Run tests
test_coin_flip()
test_random_quote()
test_random_number()
test_random_password()
test_random_dice()
```