Skip to content

Nkasi-e/social-api

Repository files navigation

SOCIAL-HUB

Social Hub API Coverage Status

An API that allows users to create contents

This API was build using the python fastapi framework

Features

  • Anybody can create an account and become a user.
  • Authenticated users can login to their individual account.
  • Authenticated users can create posts.
  • Authenticated users can read personal posts.
  • Authenticated users can view everybody's posts.
  • Authenticated users can view a specific post.
  • Authenticated users can delete personal post.
  • Authenticated users can update personal post.
  • Authenticated users can can like any post of their choice.
  • Authenticated users can can unlike any post of their choice.
  • Can get a specific user by Id.
  • Users have the ability to search for keywords and get back response if it matches any keyword in the post content available on the database
  • Users have the ability to set pagination, default pagination is set to 10

API Documentation

API documentation:

Models

Users

field data_type constraints validation
id Object required None
email string required unique, email must conform to email (example: [email protected])
password string required pasword must contain at least one uppercase, one lowercase, one number, and must be at least 8 characters
created_at timestamp automatically set

Posts

field data_type constraints validation
id integer required None
title string required None
content string required None
publised boolean optional, default value set to false None
created_at timestamp required, automatically set

Likes

field data_type constraints validation
user_id integer required None
post_id integer required None

Home Page

  • Route: /
  • Method: GET
  • Header
    • Authorization: None
  • Responses: Success
{
  "message": "Welcome to Social Hub"
}

Signup User

  • Route: /users
  • Method: POST
  • Header
    • Authorization: None
  • Body:
{
  "email": "[email protected]",
  "password": "Password123"
}
  • Responses: Success
{
  "id": 1,
  "email": "[email protected]",
  "created_at": "2023-02-05T15:29:24.712Z"
}

Login User

  • Route: /login
  • Method: POST
  • Body:
{
  "username": "[email protected]",
  "password": "Password123"
}
  • Responses: Success
{
  "access_token": "accesstokenexample&8ofiwhb.fburu276r4ufhwu4.o82uy3rjlfwebj",
  "token_type": "Bearer"
}

Create Post

  • Route: /posts
  • Method: POST
  • Header
    • Authorization: Bearer {token}
  • Body:
{
  "title": "string",
  "content": "string",
  "published": true
}
  • Responses: Success
{
  "title": "string",
  "content": "string",
  "published": true,
  "id": 0,
  "created_at": "2023-02-05T19:02:41.204Z",
  "owner_id": 0,
  "owner": {
    "id": 0,
    "email": "[email protected]",
    "created_at": "2023-02-05T19:02:41.204Z"
  }
}

Get Post

  • Route: /posts
  • Method: GET
  • Header
    • Authorization: Bearer {token}
  • Body:
[
  {
    "Post": {
      "title": "string",
      "content": "string",
      "published": true,
      "id": 4,
      "created_at": "2023-02-05T19:10:08.030Z",
      "owner_id": 4,
      "owner": {
        "id": 4,
        "email": "[email protected]",
        "created_at": "2023-02-05T19:10:08.030Z"
      }
    },
    "likes": 0
  }
  {
    "Post": {
      "title": "string",
      "content": "string",
      "published": true,
      "id": 1,
      "created_at": "2023-02-05T19:10:08.030Z",
      "owner_id": 2,
      "owner": {
        "id": 2,
        "email": "[email protected]",
        "created_at": "2023-02-05T19:10:08.030Z"
      }
    },
    "likes": 4
  }
  {
    "Post": {
      "title": "string",
      "content": "string",
      "published": true,
      "id": 3,
      "created_at": "2023-02-05T19:10:08.030Z",
      "owner_id": 2,
      "owner": {
        "id": 2,
        "email": "[email protected]",
        "created_at": "2023-02-05T19:10:08.030Z"
      }
    },
    "likes": 2
  }
]

Getting Started

Prerequisites

In order to run this project locally, you would need to have the following installed on your local machine.

  • Python ^3.10,
  • PostgreSQL
  • Docker - optional

Installation

  • Clone this repository
git clone [https://github.com/Nkasi-e/social-api.git]
  • update env with .env.example.txt
  • Download all dependecies using pip install -r requirements.txt or pipenv install that's if you have pipenv installed already on your machine
  • run uvicorn app.main:app --reload