Coder Social home page Coder Social logo

fast-api's Introduction

fastapi


๐Ÿ›  FastAPI Social Media App ๐Ÿ› 


home

home


FastAPI Social Media App

Description

This repository contains the code for a social media application built with FastAPI, a modern Python web framework. The application provides functionalities for users to create, read, update, and delete posts, as well as like and favorite posts. Users can also register, login, and manage their profiles.

Features

User Management(Dockerized)

  • Registration: Users can register by providing a unique username, email, password, age, and gender.
  • Authentication: Authentication is handled using JWT tokens. Upon successful login, users receive an access token which they can use to authenticate subsequent requests.
  • Profile Management: Users can update their profile information, such as username, email, password, age, and gender.
  • User Deletion: Users can delete their accounts.

Post Management(Dockerized)

  • Create Post: Authenticated users can create new posts with a title, content, location, and specify if the post is published or not.
  • Read Post: Users can view posts, which include details like the title, content, author, creation date, number of likes, and comments.
  • Update Post: Users can update their own posts, including modifying the title, content, and published status.
  • Delete Post: Users can delete their own posts.

Like and Favorite(Dockerized)

  • Like Post: Users can like posts they find interesting. They can only like a post once.
  • Favorite Post: Users can add posts to their favorites list for quick access. They can also remove posts from their favorites.

Search(Dockerized)

  • Search Posts: Users can search for posts by title.

Technologies Used

  • FastAPI: A modern Python web framework for building APIs with Python type hints.

  • SQLAlchemy: A SQL toolkit and Object-Relational Mapping (ORM) library for Python.

  • PostgreSQL: A powerful, open-source relational database system.

  • Pydantic: Data validation and settings management using Python type annotations.

  • JWT (JSON Web Tokens): Authentication mechanism for securing API endpoints.

  • Passlib: Password hashing library for securely storing passwords.

  • Docker: A platform for developing, shipping, and running applications in containers, providing a consistent environment across different systems.

  • Docker Compose: A tool for defining and running multi-container Docker applications, simplifying the process of managing complex containerized environments.


API Endpoints

Post

METHOD ROUTE FUNCTIONALITY ACCESS
GET /posts Get_All_Posts All users
POST /posts Create Post All users
GET /posts/{id} Get Post By Id All users
PUT /posts/{id} Update Post All users
DELETE /posts/{id} Delete Post All users

User

METHOD ROUTE FUNCTIONALITY ACCESS
GET /users Get_All_Users All users
POST /users Create User All users
GET /users/{id} Get User By Id All users
PUT /users/{id} Update User All users
DELETE /users/{id} Delete User All users

Authentications

METHOD ROUTE FUNCTIONALITY ACCESS
POST /login Login user(jwt) All users

Likes

METHOD ROUTE FUNCTIONALITY ACCESS
POST /likes Like Post All users

Favorites

METHOD ROUTE FUNCTIONALITY ACCESS
POST /favorite Favorite Post All users

Installation

1- Clone the repository:

git clone https://github.com/yourusername/fast-api.git

2- Create your virtualenv and activate it:

Pipenv or virtualenv

3- Install dependencies:

pip install -r requirements.txt

4- Configure environment variables: Create a .env file and set the following variables:

DATABASE_HOSTNAME=your_database_hostname
DATABASE_PORT=your_database_port
DATABASE_NAME=your_database_name
DATABASE_USERNAME=your_database_username
DATABASE_PASSWORD=your_database_password
SECRET_KEY=your_secret_key
ALGORITHM=your_algorithm
ACCESS_TOKEN_EXPIRE_MINUTES=your_access_token_expire_minutes

5- Run the application:

uvicorn app.main:app --reload


Example Requests

Create User

Request

POST /users/
Content-Type: application/json

{
  "username": "example_user",
  "email": "[email protected]",
  "password": "securepassword",
  "age": 25,
  "gender": "male",
  "is_active": true
}

Response

HTTP/1.1 201 Created
Content-Type: application/json

{
  "id": 1,
  "username": "example_user",
  "email": "[email protected]",
  "age": 25,
  "gender": "male",
  "is_active": true,
  "created_at": "2024-04-04T12:00:00",
  "updated_at": "2024-04-04T12:00:00"
}

Create Post

Request

POST /posts/
Authorization: Bearer <access_token>
Content-Type: application/json

{
  "title": "Example Post",
  "content": "This is an example post content.",
  "published": true,
  "location": "New York, USA"
}

Response

HTTP/1.1 201 Created
Content-Type: application/json

{
  "id": 1,
  "title": "Example Post",
  "content": "This is an example post content.",
  "published": true,
  "location": "New York, USA",
  "comments": 0,
  "created_at": "2024-04-04T12:00:00",
  "updated_at": "2024-04-04T12:00:00",
  "user_id": 1,
  "owner": {
    "id": 1,
    "username": "example_user",
    "email": "[email protected]",
    "is_active": true
  }
}

Create Like

Request

POST /likes/
Authorization: Bearer <access_token>
Content-Type: application/json

{
  "post_id": 1,
  "dir": 1
}

Response

HTTP/1.1 201 Created
Content-Type: application/json

{
  "message": "User 1 liked post 1"
}

Acknowledgments

  • FastAPI Community
  • SQLAlchemy Community
  • Python Community

License

This project is licensed under the MIT License.


Built with โค๏ธ by Payam Anari

Thank you for exploring the Gym Fitness app! If you have any questions, feedback, or just want to say hi, feel free to reach out. Happy fitness journey!


fast-api's People

Contributors

payamanari avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.