Skip to content

MohammadOshkooh/BlogAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⭐ Technologies used in blog api

  • Django
  • Python
  • Django rest framework
  • Django allauth
  • Dj rest auth
  • JWT cookie authentication

Steps to Setup

1. Clone the application

git clone https://github.com/MohammadOshkooh/blog.api

2. install dependencies

pip install -r requirements.txt

3. migrate

python manage.py migrate

4. Run

python manage.py runserver

The app will start running at http://localhost:8000

Explore Rest APIs

The app defines following CRUD APIs.

Auth

Method Url Description
POST /logout/ Sign up
POST /login/ Log in

Users

Method Url Description
GET /user/ Get logged in user profile
GET /api/users/{userid}/ Get user profile by username
GET /api/users/{userid}/posts Get posts created by user
POST /api/users Add user (Only for admins)
PUT /api/users/{userid} Update user (If profile belongs to logged in user or logged in user is admin)
DELETE /api/users/{userid} Delete user (For logged in user or admin)

Posts

Method Url Description
GET /api/posts Get all posts
GET /api/posts/{id} Get post by id
POST /api/posts Create new post (By logged in user)
PUT /api/posts/{id} Update post (If is owner or is admin)
DELETE /api/posts/{id} Delete post (If is owner or is admin)

Comments

Method Url Description
GET /api/posts/{postId}/comments Get all comments which belongs to post with id = postId
GET /api/posts/{postId}/comments/{id} Get comment by id if it belongs to post with id = postId
POST /api/posts/{postId}/comments Create new comment for post with id = postId (By logged in user)
PUT /api/posts/{postId}/comments/{id} Update comment by id if it belongs to post with id = postId (If is comment owner or is admin)
DELETE /api/posts/{postId}/comments/{id} Delete comment by id if it belongs to post with id = postId (If is comment owner or is admin)

Sample Valid JSON Request Body

{
  "username": "test_user",
  "password1": "test_pass",
  "password2": "test_pass",
  "email": "test@test.com"
}
{
  "username": "test_user",
  "password": "test_pass"
}
{
  "firstName": "mohammad",
  "lastName": "mohammadi",
  "username": "test_username",
  "password": "updatedpassword",
  "email": "mohammad.mohammadi@gmail.com"
}
{
  "title": "test tile",
  "body": " this is a body."
}
{
  "title": "updated title",
  "body": "UPDATED UPDATED UPDATED UPDATED UPDATED UPDATED UPDATED UPDATED UPDATED UPDATED UPDATED UPDATED "
}
{
  "body": "this is a comment"
}
{
  "body": "UPDATED UPDATED UPDATED UPDATED UPDATED UPDATED UPDATED UPDATED UPDATED UPDATED "
}