Skip to content

Latest commit

 

History

46 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Blog Application API

This is a RESTful API for a blog application built with Django and Django REST Framework. It supports basic CRUD operations for blog posts and comments. This Project is live on https://sdcblogproject.onrender.com/api/blogs/

Features

  • User registration and authentication using JWT tokens.
  • Create, read, update, and delete blog posts.
  • Add comments to blog posts.

API Endpoints

Authentication

  • POST /register/

    • Register a new user.
    • Headers:
      {
        "content-type" : "application/json"
      }
    • Request Body:
      {
        "username": "your_username",
        "password": "your_password",
        "email": "your_email@example.com"
      }
  • POST /login/

    • Obtain a Json web token by providing username and password.
    • Headers:
      {
        "content-type" : "application/json"
      }
    • Request Body:
      {
        "username": "your_username",
        "password": "your_password"
      }
    • Response:
      {
        "access": "your_access_token",
        "refresh": "your_refresh_token",
        "author_id": "your_author_id"
      }
  • GET /refresh_token/

    • Obtain a new access token by providing the refresh token.

    • Response:

      {
        "access": "your_access_token",
        "refresh": "your_refresh_token"
      }

Blog Posts

  • POST /api/blogs/

    • Create a new blog post.
    • Headers:
      {
        "authorization" : "Bearer your_jwt_access_token"
      }
    • Request Body:
      {
        "title": "Your Blog Title",
        "content": "Your blog content here.",
        "author_id": "your_author_id"
      }
    • Files:
      {
        "images" : "<your-image-file>"
      }
  • GET /api/blogs/

    • Retrieve a list of all blog posts.
  • GET /api/blogs/{blog_id}/

    • Retrieve a specific blog post by its ID.
  • PUT /api/blogs/{blog_id}/

    • Update an existing blog post by its ID.
    • Request Body:
      {
        "title": "Updated Blog Title",
        "content": "Updated blog content.",
        "author_id": "your_author_id"
      }
  • DELETE /api/blogs/{blog_id}/

    • Delete a blog post by its ID.
    • Request Body:
      {
        "author_id": "your_author_id"
      }

Comments

  • POST /api/blogs/{blog_id}/comments/
    • Add a comment to a blog post.
    • Request Body:
      {
        "blog" : "blog_id",
        "comment_text": "This is a comment.",
        "author_id" : "your_author_id"
      }

Like

  • PUT /api/blogs/{blog_id}/like/
    • Add a like to a blog post.
    • Request Body:
      {
        "author_id" : "your_author_id"
      }

Usage

  1. Set Up Environment

    • Create a .env file in the project root directory with the following contents:
      DATABASE_URL=your_database_url
      SECRET_KEY=your_secret_key
      DEBUG=True
      ALLOWED_HOSTS=allowed-hosts
      SUPERUSER_SECRET_KEY = secret-key-to-create-super-user
      //Create an account on cloudinary and get this info
      CLOUDINARY_URL = your_cloudinary_url
      CLOUDINARY_CLOUD_NAME = your_cloudinary_cloud_name
      CLOUDINARY_API_KEY = your_cloudinary_api_key
      CLOUDINARY_API_SECRET = your_cloudinary_api_secret
      
  2. Install Dependencies

    • Run the following command to install the required packages:
      pip install -r requirements.txt
  3. Migrate Database

    • Run the migrations to set up the database:
      python manage.py makemigrations
      python manage.py makemigrations blog_app
      python manage.py migrate
  4. Run the Server

    • Start the development server:
      python manage.py runserver
  5. Testing the API

About

Blog Application API: A RESTful API built with Django and Django REST Framework for managing blog content, featuring user authentication, blog post CRUD operations, and a commenting system. Ideal for developers looking to implement a flexible and robust blogging platform.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages