Skip to content

ft-ally/meddit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MEDDIT

A Reddit-like REST API built with ASP.NET Core 8 + Entity Framework Core + SQLite.

Stack

Layer Tech
Framework ASP.NET Core 8 Web API
ORM Entity Framework Core 8
Database SQLite (zero setup)
Docs Swagger / OpenAPI

Getting started

Prerequisites

Run it

cd RedditCloneApi
dotnet run

The database (reddit.db) is created automatically with seed data on first run.

Open http://localhost:5000 → Swagger UI with all endpoints.


Data model

User ──< Post >── Subreddit
User ──< Comment (self-referential for replies)
User ──< Vote ──> Post | Comment

REST Endpoints

Users

Method Route Description
GET /api/users List all users
GET /api/users/{id} Get user by ID
GET /api/users/{id}/posts Get a user's posts
POST /api/users Create user
PATCH /api/users/{id} Update user email

Create user:

POST /api/users
{ "username": "ally", "email": "ally@email.com" }

Subreddits

Method Route Description
GET /api/subreddits List all subreddits
GET /api/subreddits/{id} Get subreddit
GET /api/subreddits/{id}/posts?sort=top&limit=25 Get posts (sort: new/top)
POST /api/subreddits Create subreddit
PATCH /api/subreddits/{id} Update description

Posts

Method Route Description
GET /api/posts?sort=new&limit=25 Feed (sort: new/top)
GET /api/posts/{id} Get post
GET /api/posts/{id}/comments Get comments on a post
POST /api/posts Create post
PATCH /api/posts/{id} Edit title/body
POST /api/posts/{id}/vote Upvote or downvote

Create post:

POST /api/posts
{
  "title": "webserv amirite?",
  "body": "webserv blablablablabala",
  "userId": 2,
  "subredditId": 2
}

Vote on a post:

POST /api/posts/2/vote
{ "userId": 1, "value": 1 }   // 1 = upvote, -1 = downvote

Comments

Method Route Description
GET /api/comments/{id} Get comment
POST /api/comments Add comment (or reply)
PATCH /api/comments/{id} Edit comment body
POST /api/comments/{id}/vote Upvote or downvote

Reply to a comment:

POST /api/comments
{
  "body": "poll is not my friend",
  "userId": 1,
  "postId": 2,
  "parentCommentId": null    // null = top-level; set an ID for a reply
}

Seed data

On first run, the database is pre-seeded with:

  • 2 users: ally, ally2
  • 2 subreddits: subreddit1, subreddit2
  • 2 posts, 1 comment

Project structure

RedditCloneApi/
├── Controllers/
│   ├── UsersController.cs
│   ├── SubredditsController.cs
│   ├── PostsController.cs
│   └── CommentsController.cs
├── Data/
│   └── AppDbContext.cs       ← EF Core DbContext + seed
├── DTOs/
│   └── DTOs.cs               ← Request / response records
├── Migrations/
│   └── ...                   ← Auto-applied on startup
├── Models/
│   └── Models.cs             ← User, Post, Comment, Vote, Subreddit
└── Program.cs                ← App setup, Swagger

About

Side project built to learn and practice C#, MySQL, Entity Framework, and REST API development. Meddit is a REST API which enables users to post, comment and vote on topics. Inspired by a popular forum that rhymes with Weddit.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages