JWT (JSON Web Token) is a second authentication scheme offered by the API alongside Token auth. The key difference: instead of one token, you get two.
- Access token — short-lived (minutes or hours). You send this on every request.
- Refresh token — long-lived (days). You only use it to get a new access token when the old one expires.
Why two tokens? If an access token is stolen, it can only be misused for a short time. The refresh token stays safe because it travels less frequently — only when renewing access.
The authorization header format for JWT uses 'Bearer' instead of 'Token':
```
Authorization: Bearer <access_token>
```
In requests:
```python
import requests
BASE_URL = 'https://apilearn.tukas.dev'
access_token = '...'
headers = {'Authorization': f'Bearer {access_token}'}
response = requests.get(f'{BASE_URL}/api/users/profile/', headers=headers)
```
When the access token expires, you do not need to ask the user for credentials again. Send the refresh token to the refresh endpoint and you get a fresh access token back:
```python
response = requests.post(
f'{BASE_URL}/api/auth/jwt/refresh/',
json={'refresh': refresh_token},
)
new_access = response.json()['access']
```
Token auth vs JWT — when to prefer which:
- Token auth is simpler: one token, straightforward header, no expiry to manage.
- JWT is more secure for long-lived sessions: access tokens expire quickly, reducing risk if intercepted. Standard in modern mobile apps and SPAs.
For scripts and short-lived automation, Token auth is often enough. JWT becomes important when you are building something that stays authenticated over days or weeks.
POST to /api/auth/jwt/ with your username and password. Print the first 30 characters of both the access and refresh tokens.
import requests
BASE_URL = 'https://apilearn.tukas.dev'
credentials = {'username': 'YOUR_USERNAME', 'password': 'YOUR_PASSWORD'}
# Get JWT pair and print the first 30 chars of each token
Get a JWT pair, then immediately use the refresh token to get a new access token via POST /api/auth/jwt/refresh/. Print the new access token (first 30 characters).
import requests
BASE_URL = 'https://apilearn.tukas.dev'
# 1. Get initial token pair
# 2. Use refresh token to get a new access token
# 3. Print the first 30 chars of the new access token
Write a function refresh_access(refresh_token) that returns a new access token using the refresh endpoint. Then write a small script that gets the initial pair and immediately refreshes the access token, printing both the original and new access tokens (first 20 characters each).
import requests
BASE_URL = 'https://apilearn.tukas.dev'
def refresh_access(refresh_token):
# POST to /api/auth/jwt/refresh/ and return the new access token
pass
# Get initial pair, then refresh
We use necessary cookies to run the site. With your permission, we can also save your site preferences and use analytics and advertising cookies to understand usage and support the project.
Open tools in tabs.Exercises, IDE tools, and trainers stay available as site tabs.
Switch without losing context.Move between explanations, code, and utilities while keeping your place.
Use the sidebar as your map.The left panels hold navigation, settings, files, libraries, and tool controls.
PythonJavaScriptSQLite
One IDE, three practical modes
Python in the browser.Run small scripts, try libraries, and practice API requests without installing anything.
JavaScript for quick experiments.Test browser-friendly code and compare ideas next to your learning materials.
SQLite for data practice.Open the database explorer to inspect tables, write queries, and learn SQL workflows locally.
TopicIDE
Work side by side with split tabs
Keep instructions visible.Open an exercise or reference page beside the IDE instead of jumping back and forth.
Compare tools while you learn.Place regex checks, explanations, and code experiments next to each other when the task needs it.
Close the split when you are done.The workspace returns to a single focused tab, and your open site tabs remain available.
Code Typing Trainer
Or plain text
This trainer is designed for a physical keyboard.Open this section on a laptop or desktop with a wide screen. Touch typing practice will not work correctly on a phone.
Speed: 0 chars/min
0 words/min
Best speed (60s): 0 chars/min
0 words/min
Errors: 0
Total time: 0.0 s
To practice touch typing, avoid looking at your physical keyboard.