A Reddit-like REST API built with ASP.NET Core 8 + Entity Framework Core + SQLite.
| Layer | Tech |
|---|---|
| Framework | ASP.NET Core 8 Web API |
| ORM | Entity Framework Core 8 |
| Database | SQLite (zero setup) |
| Docs | Swagger / OpenAPI |
cd RedditCloneApi
dotnet runThe database (reddit.db) is created automatically with seed data on first run.
Open http://localhost:5000 → Swagger UI with all endpoints.
User ──< Post >── Subreddit
User ──< Comment (self-referential for replies)
User ──< Vote ──> Post | Comment
| 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" }| 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 |
| 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| 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
}On first run, the database is pre-seeded with:
- 2 users:
ally,ally2 - 2 subreddits:
subreddit1,subreddit2 - 2 posts, 1 comment
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