Closed jacob-macleod closed 2 months ago
The first stage is to test the current API methods to understand them. To do this, you can use an app called insomnia - https://insomnia.rest/download. Let me know if you need more info, but you do the following:
backend/database/database_config.py
stores type="local"
to write to local files and not the actual database (for development and testing`pip3 install -r requirements.txt
to the terminalpython3 backend/main.py
to the terminal
This will tell you the URL the backend API server is running atNote that if you don't use insomnia, you can go to a URL in your browser, but I don't think you can add json data to tell it userID and things like that.
Then, open insomnia:
/api/create-account
from https://github.com/jacob-macleod/Flashcard-App/blob/main/backend/routes/api/authentication.py/api/create-account
. Select the POST
method because in the code for that route it says methods=["POST"]
json
in the text area of insomnia. Enter the following:
{
"userID":"my-id",
"displayName": "my-name"
}
You can change the string values if you want, When you're ready, press the button to go to the route. A 200 OK message should be returned, telling you there were no errors. Open data.json
, and you'll see that your new data has been added. Try this with a few more API routes to get a feel for how it works.
You'll need to do this to create an account so that when you read a user's totalXP, there will actually be a user. When you write the code to get a user's XP, and test it in insomnia, you will be passing it a json file that looks similar to this:
{
"userID":"my-id"
}
Provided you tell it to accept that in the code. my-id
will need to be the ID of an existing user stored in data.json
If you have any questions, please ask!
(This issue is not ready to be worked on yet)
This is now done
Here, you can see the total XP (6093). The dashboard page is in development, and an API route needs to be written to read the total XP from the database and return it.
How the code works is:
backend/main.py
runs a serverfrontend/
displays the UI, and gets data frombackend/main.py
using the API, which is basically a function that does some processing returns a value that can be accessed over the internet. The frontend code knows to go tohttp://dolphinflashcards.com.api/<whatever api function is being called>
because that is stored as a variable in a file in thefrontend
folderEvery API request is made with json data, which provides information needed for the request
Your code will go in
backend/routes/api/statistics.py
. The format of each function that already exists is as follows - below you can see a simplified existing function with some comments:.