URLs

This API contains the following endpoints

POST /api/newroulette/

Creates a new roulette in the database and returns its id

Request Headers
Status Codes
  • 200 OK – Creation successful

Body

not required

Example Request:

http

POST /api/newroulette/ HTTP/1.1
Host: localhost:8000
Accept: application/json
Content-Type: application/json

curl

curl -i -X POST http://localhost:8000/api/newroulette/ -H 'Accept: application/json' -H 'Content-Type: application/json'

wget

wget -S -O- http://localhost:8000/api/newroulette/ --header='Accept: application/json' --header='Content-Type: application/json'

Example response:

HTTP/1.1 200 OK
Content-Type: application/json

{
    "roulette_id": "fe87376f-61bf-4b12-beac-98ec2b019840"
}
POST /api/openroulette/

Opens a roulette for a given id and validates if the id exists or the roulette is already open

Request Headers
Status Codes
Body

application/json

Body

{"roulette_id":"<rouletteid>"}

Example Request:

http

POST /api/openroulette/ HTTP/1.1
Host: localhost:8000
Accept: application/json
Content-Type: application/json

{"roulette_id":"d215d481-a0fb-47d7-bd69-d6b731b01c04"}

curl

curl -i -X POST http://localhost:8000/api/openroulette/ -H 'Accept: application/json' -H 'Content-Type: application/json' --data-raw '{"roulette_id": "d215d481-a0fb-47d7-bd69-d6b731b01c04"}'

wget

wget -S -O- http://localhost:8000/api/openroulette/ --header='Accept: application/json' --header='Content-Type: application/json' --post-data='{"roulette_id": "d215d481-a0fb-47d7-bd69-d6b731b01c04"}'

Example response:

HTTP/1.1 200 OK
Content-Type: application/json

{
    "status": "OPEN"
}
HTTP/1.1 400 Bad Request
Content-Type: application/json

{
    "error": "Roulette is already open"
}
HTTP/1.1 400 Bad Request
Content-Type: application/json

{
    "error:Roulette does not exist"
}
POST /api/betroulette/

Registers a bet for a given user id validates the amount, the roulette id and the number

Request Headers
Status Codes
Body

application/json

Body

{"number":"<number to bet>","amount":"<amount>","roulette_id":"<roulette_id>"}

Example Request:

http

POST /api/betroulette/ HTTP/1.1
Host: localhost:8000
Accept: application/json
Content-Type: application/json

{"number":"12","amount":100,"roulette_id":"d215d481-a0fb-47d7-bd69-d6b731b01c04"}

curl

curl -i -X POST http://localhost:8000/api/betroulette/ -H 'Accept: application/json' -H 'Content-Type: application/json' --data-raw '{"amount": 100, "number": "12", "roulette_id": "d215d481-a0fb-47d7-bd69-d6b731b01c04"}'

wget

wget -S -O- http://localhost:8000/api/betroulette/ --header='Accept: application/json' --header='Content-Type: application/json' --post-data='{"amount": 100, "number": "12", "roulette_id": "d215d481-a0fb-47d7-bd69-d6b731b01c04"}'

Example response:

HTTP/1.1 200 OK
Content-Type: application/json

{
     "status": "Bet Registered"
}
HTTP/1.1 400 Bad Request
Content-Type: application/json

{
    "error": "Bet exceeds the maximum amount"
}
HTTP/1.1 400 Bad Request
Content-Type: application/json

{
    "error": "Invalid number, please try again"
}

Note

This endpoint supports and calculates “RED” and “BLACK” as number field

POST /api/closeroulette/

Closes a open roulette and returns its results

Request Headers
Status Codes
Body

application/json

Body

{"roulette_id":"<roulette_id>"}

Example Request:

http

POST /api/close_roulette/ HTTP/1.1
Host: localhost:8000
Accept: application/json
Content-Type: application/json

{"roulette_id":"d215d481-a0fb-47d7-bd69-d6b731b01c04"}

curl

curl -i -X POST http://localhost:8000/api/close_roulette/ -H 'Accept: application/json' -H 'Content-Type: application/json' --data-raw '{"roulette_id": "d215d481-a0fb-47d7-bd69-d6b731b01c04"}'

wget

wget -S -O- http://localhost:8000/api/close_roulette/ --header='Accept: application/json' --header='Content-Type: application/json' --post-data='{"roulette_id": "d215d481-a0fb-47d7-bd69-d6b731b01c04"}'

Example response:

HTTP/1.1 200 OK
Content-Type: application/json

{
"winner_number": "3",
"results": [
    {
        "win": 0,
        "user": "User1",
        "amount": 1000
    },
    {
        "win": 0,
        "user": "User2",
        "amount": 1000
    },

    ]
}
HTTP/1.1 400 Bad Request
Content-Type: application/json

{
    "error": "Roulette already closed"
}
HTTP/1.1 400 Bad Request
Content-Type: application/json

{
    "error": "Roulette does not exists"
}
POST /api/listroulette/

List the results of a closed roulette

Request Headers
Status Codes
Body

application/json

Body

{"roulette_id":"<roulette_id>"}

Example Request:

http

POST /api/listroulette/ HTTP/1.1
Host: localhost:8000
Accept: application/json
Content-Type: application/json
:body: application/json

{"roulette_id":"d215d481-a0fb-47d7-bd69-d6b731b01c04"}

curl

curl -i -X POST http://localhost:8000/api/listroulette/ -H 'Accept: application/json' -H 'Content-Type: application/json' --data-raw '{"roulette_id": "d215d481-a0fb-47d7-bd69-d6b731b01c04"}'

wget

wget -S -O- http://localhost:8000/api/listroulette/ --header='Accept: application/json' --header='Content-Type: application/json' --post-data='{"roulette_id": "d215d481-a0fb-47d7-bd69-d6b731b01c04"}'

Example response:

HTTP/1.1 200 OK
Content-Type: application/json

{
"winner_number": "3",
"results": [
    {
        "win": 0,
        "user": "User1",
        "amount": 1000
    },
    {
        "win": 0,
        "user": "User2",
        "amount": 1000
    },

    ]
}
HTTP/1.1 400 Bad Request
Content-Type: application/json

{
     "error": "Roulette still open"
}
HTTP/1.1 400 Bad Request
Content-Type: application/json

{
    "error": "Roulette does not exists"
}
POST /api/createuser/

Creates a new user in order to make future bets

Request Headers
Status Codes
  • 200 OK – Creation successful

Body

application/json

Body

{"username":"<username>","password":"<password>"}

Example Request:

http

POST /api/createuser/ HTTP/1.1
Host: localhost:8000
Accept: application/json
Content-Type: application/json

{"username":"User3","password":"User3"}

curl

curl -i -X POST http://localhost:8000/api/createuser/ -H 'Accept: application/json' -H 'Content-Type: application/json' --data-raw '{"password": "User3", "username": "User3"}'

wget

wget -S -O- http://localhost:8000/api/createuser/ --header='Accept: application/json' --header='Content-Type: application/json' --post-data='{"password": "User3", "username": "User3"}'

Example response:

HTTP/1.1 200 OK
Content-Type: application/json

{
    "status": "user created successfully"
}

Note

you can list the users and tokens (required in the betroulette endpoint) in the django admin panel http://127.0.0.1:8000/admin/ username: admin, password: admin