Giter VIP home page Giter VIP logo

chaindots-challenge's Introduction

Social Media API

This Django API provides endpoints for a social media platform that allows users to create posts, follow other users, and comment on posts.

Requirements

  • Python 3.7 or higher
  • Django 3.2 or higher
  • Django REST framework

Installation

Clone the repository:

$ git clone <repository-url>
$ cd social-media-api

Create and activate a virtual environment:

$ python3 -m venv env
$ source env/bin/activate

Install the dependencies:

$ pip install -r requirements.txt

Set up the database:

$ python manage.py migrate

Create a superuser:

$ python manage.py createsuperuser

Run the development server:

$ python manage.py runserver

The API should now be running locally at http://127.0.0.1:8000/api/users.

API Endpoints

GET /api/users/: Retrieve a list of all users.
GET /api/users/{id}/: Retrieve details of a specific user.
POST /api/users/{id}/follow/{id}: Set the first user as a follower of the second user.
POST /api/users/: Create a new user.
GET /api/posts/: Retrieve a list of all posts with pagination and filters.
GET /api/posts/{id}/: Retrieve details of a specific post with its last three comments included.
POST /api/posts/: Create a new post.
GET /api/posts/{id}/comments/: Retrieve all comments for a specific post.
POST /api/posts/{id}/comments/: Add a new comment to a post.

Note: All endpoints require authentication using token-based authentication.

Authorization

Token-based authentication is used to authenticate API requests. To authenticate, include the token in the request header.

Token "token-value" To obtain a token, you can use the Django shell or authenticate through a login endpoint.

To create a token using the Django shell, run the following command:

$ python manage.py drf_create_token <username>

output:
    python manage.py drf_create_token user1
    Generated token 7baa3db5c2f07f617c87616716e689ca7c6692a8 for user user1

Note: You can use Postman to authenticate through a create user endpoint. To do so, send a POST request to http://127.0.0.1:8000/api/users with the username, password and followers list (could be an empty list) in the request body. The response will include the token.

Running Tests:

To run the unit tests for the API endpoints and ORM queries, use the following command:

$ python manage.py test

Optimization and Performance:

The project includes optimizations such as indexing and constraints on database fields to improve query performance. These optimizations aim to minimize the number of database hits and enhance overall performance.

Contributing:

Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.

License

This project is licensed under the MIT License.

chaindots-challenge's People

Contributors

jose-cabrera-fullstack 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.