A REST API in django for a mobile game
- Install python3 (
apt-get install python3
) - Install pip3 (
apt-get install python3-pip
) - Install virutalenv (
python3 -m venv env
) - Activate the environment (
source env/bin/activate
) - Install requirements (
pip install -r requirements.txt
)
When you are done, use: deactivate
to exit the virutal environment.
To update requirements just run step 6 again.
- Activate the environment (
source env/bin/activate
) - Install the package using pip
- run
pip freeze --local > requirements.txt
- Create a user (python manage.py createsuperuser).
- Go to localhost:8000/admin and log in with your user.
- Go to the table "Tokens".
- Press "Add token".
- Choose your user an press "SAVE".
You should now see a token that look like: "02ffe8c6c2851ccc8b458e39049d6b4f94be5a25"
- Go to localhost:8000/admin and log in with your user.
- Go to localhost:8000 and you should now have access to the api.
Get all scores
- curl -X GET 'http://localhost:8000/scores/' -H 'Authorization: Token 02ffe8c6c2851ccc8b458e39049d6b4f94be5a25'
Add new score
- curl -X POST 'http://localhost:8000/scores/' -H 'Content-Type: application/json' -H 'Authorization: Token 02ffe8c6c2851ccc8b458e39049d6b4f94be5a25' -d '{"user": "http://localhost:8000/users/1/", "score":"1337"}'