It's simple REST API for everyday social network.
Created using Django-Rest-Framework using JWT authentication
Basic Features:
- User signup
- User login
- Post creation
- Like post
- Unlike post
pip install requirements.txt
- Run tests...
python manage.py test
-
Add
.env
file to main andautomated_bot/
directories. -
And if everything all right start server.
python manage.py runserver
1. Sign up example.
{
"username": "test",
"email": "[email protected]",
"password": "password",
"double_password": "password"
}
2. Login example.
{
"username": "test",
"password": "password"
}
3. Post creation example.
{
"title": "test",
"description": "I love testing!"
}
4. Post like/unlike example.
{
"post_id": "test"
}
5. Analytics point example.
GET /facebook/api/analitics/?date_from=2020-02-02&date_to=2020-02-15
6. Activity point example.
GET /facebook/api/activity/?username=test
{
"last_login": "2021-07-19 11:31:55",
"last_request": "2021-07-19 11:48:37"
}
1. Override default User model
2. Override default UserManager model
3. Add rest_framework_simplejwt library
INSTALLED_APPS += [
'rest_framework_simplejwt'
]
automated_bot/
python async_bot.py
2.The bot use data from automated_bot/.env</
file
number_of_users=5
max_posts_per_user=7
max_likes_per_user=8
-
Sign Up
number_of_users
users -
Each user creates random number of posts, but maximum
max_posts_per_user
-
Each user randomly like
max_likes_per_user
posts
1. Сheck password strength
2. Add lifetime for tokens
SIMPLE_JWT = {
'ACCESS_TOKEN_LIFETIME': timedelta(minutes=30),
'REFRESH_TOKEN_LIFETIME': timedelta(days=1),
}
3. Add throttling to your views. Configure it for yourself.
# settings.py
REST_FRAMEWORK = {
'DEFAULT_THROTTLE_CLASSES': [
'rest_framework.throttling.AnonRateThrottle',
'rest_framework.throttling.UserRateThrottle'
],
'DEFAULT_THROTTLE_RATES': {
'anon': '50/day',
'user': '1000/day'
}
# views.py
class RegisterAPIView(APIView):
throttle_classes = [AnonRateThrottle]