Skip to content

KuzenkovAG/api_yatube_final

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

API for Yatube v.0.2.0

API services for Yatube project

Features

  • User registration
  • JWT authentication
  • Create or update own Posts
  • View Posts
  • Become follower of other user

Tech

  • Python 3.9
  • Django REST Framework
  • JWT

History

Installation (for Windows)

Clone repository

git clone git@github.com:KuzenkovAG/api_yatube_final.git

Install environment

cd api_yatube_final/
python -m venv venv

Activate environment

source venv/Scripts/activate

Install requirements

pip install -r requirements.txt

Make migrate

python yatube_api/manage.py migrate

Run server

python yatube_api/manage.py runserver

Usage

Create User / get JWT

POST /api/jwt/create/
{
    "username": "string",
    "password": "string"
}

Response:
{
    "refresh": "string",
    "access": "string"
}

Receive posts

GET /api/v1/posts/

Response:
{
  "count": 123,
  "next": "http://api.example.org/accounts/?offset=400&limit=100",
  "previous": "http://api.example.org/accounts/?offset=200&limit=100",
  "results": [
    {
      "id": 0,
      "author": "string",
      "text": "string",
      "pub_date": "2021-10-14T20:41:29.648Z",
      "image": "string",
      "group": 0
    }
  ]
}

Create post

POST /api/v1/posts/
{
    "text": "string",
    "image": "string",
    "group": 0
}

Response:
{
   "id": 0,
   "author": "string",
   "text": "string",
   "pub_date": "2019-08-24T14:15:22Z",
   "image": "string",
   "group": 0
}

Receive post

GET /api/v1/posts/{id}/

Response:
{
   "id": 0,
   "author": "string",
   "text": "string",
   "pub_date": "2019-08-24T14:15:22Z",
   "image": "string",
   "group": 0
}

Update post

PUT /api/v1/posts/{id}/
{
   "text": "string",
   "image": "string",
   "group": 0
}

Response:
{
   "id": 0,
   "author": "string",
   "text": "string",
   "pub_date": "2019-08-24T14:15:22Z",
   "image": "string",
   "group": 0
}

Particle update post

PATCH /api/v1/posts/{id}/
{
   "text": "string",
   "image": "string",
   "group": 0
}

Response:
{
   "id": 0,
   "author": "string",
   "text": "string",
   "pub_date": "2019-08-24T14:15:22Z",
   "image": "string",
   "group": 0
}

Delete post

DELETE /api/v1/posts/{id}/

Receive comments

GET /api/v1/posts/{post_id}/comments/

Responce
[
   {
      "id": 0,
      "author": "string",
      "text": "string",
      "created": "2019-08-24T14:15:22Z",
      "post": 0
   }
]

Add comment

POST /api/v1/posts/{post_id}/comments/
{
   "text": "string"
}

Responce
{
   "id": 0,
   "author": "string",
   "text": "string",
   "created": "2019-08-24T14:15:22Z",
   "post": 0
}

Get comment

GET /api/v1/posts/{post_id}/comments/{id}/

Responce
{
   "id": 0,
   "author": "string",
   "text": "string",
   "created": "2019-08-24T14:15:22Z",
   "post": 0
}

Update comment

PUT /api/v1/posts/{post_id}/comments/{id}/
{
   "text": "string"
}

Responce
{
   "id": 0,
   "author": "string",
   "text": "string",
   "created": "2019-08-24T14:15:22Z",
   "post": 0
}

Delete comment

DELETE /api/v1/posts/{post_id}/comments/{id}/

Get groups

GET /api/v1/groups/

[
   {
      "id": 0,
      "title": "string",
      "slug": "string",
      "description": "string"
   }
]

Get group

GET /api/v1/groups/{id}/

{
   "id": 0,
   "title": "string",
   "slug": "string",
   "description": "string"
}

Follows

GET /api/v1/follow/

Response
[
   {
      "user": "string",
      "following": "string"
   }
]

Follow to user

POST /api/v1/follow/
{
   "following": "string"
}


Response
{
   "user": "string",
   "following": "string"
}

Refresh JWT

POST /api/v1/jwt/refresh/
{
   "refresh": "string"
}

Response
{
   "access": "string"
}

Check JWT

POST /api/v1/jwt/verify/
{
  "token": "string"
}