This is a RESTful API built with FastAPI for a Neural network.
- Clone the repository:
git clone https://github.com/your-username/social-media-api.git
2. Install the required dependencies:
```bash
pip install -r requirements.txt
- Start the server:
uvicorn main:app --reload
The API will be available at http://localhost:8000
.
- Method:
POST
- Path:
/users/
- Description: Register a new user in the system.
- Request Body: A
User
object withusername
,email
, andpassword
fields. - Response: The created
User
object without the password.
- Method:
GET
- Path:
/users/{user_id}
- Description: Retrieve information about a user by their ID.
- Path Parameter:
user_id
- The ID of the user. - Response: The
User
object without the password.
- Method:
POST
- Path:
/posts/
- Description: Create a new post.
- Request Body: A
Post
object withuser_id
,text
, and optionalmedia
fields. - Response: The created
Post
object.
- Method:
GET
- Path:
/posts/{post_id}
- Description: Retrieve a post by its ID.
- Path Parameter:
post_id
- The ID of the post. - Response: The
Post
object.
- Method:
POST
- Path:
/posts/{post_id}/like
- Description: Like a post.
- Path Parameter:
post_id
- The ID of the post. - Request Body: A
User
object with theuser_id
field. - Response: The updated
Post
object.
- Method:
POST
- Path:
/posts/{post_id}/comment
- Description: Comment on a post.
- Path Parameter:
post_id
- The ID of the post. - Request Body: A
Comment
object withuser_id
andtext
fields. - Response: The updated
Post
object.
- Method:
POST
- Path:
/posts/{post_id}/repost
- Description: Repost a post.
- Path Parameter:
post_id
- The ID of the post. - Request Body: A
User
object with theuser_id
field. - Response: The updated
Post
object.
class User(BaseModel):
id: Optional[str] = None
username: str
email: str
password: str
created_at: Optional[datetime] = None
class Post(BaseModel):
id: Optional[str] = None
user_id: str
text: str
media: List[str] = []
likes: List[str] = []
comments: List[dict] = []
reposts: int = 0
created_at: Optional[datetime] = None
updated_at: Optional[datetime] = None
class Comment(BaseModel):
user_id: str
text: str
created_at: Optional[datetime] = None