Skip to content

artemshii/MiniBlogAPI

Repository files navigation

📝 MiniBlogAPI

A lightweight GraphQLAPI built with ASP.NET Core and Entity Framework Core.
MiniBlogAPI allows users to create profiles, publish posts, like posts, search for other users, subscribe to real-time updates and much more.


🚀 Features

  • 🔐 User management (create, query by ID, list users)
  • 📰 Post creation and listing
  • ❤️ Like system
  • ⚡ Real-time subscriptions (GraphQL subscriptions for new posts)
  • 🧠 Built with:
    • ASP.NET Core / EF Core
    • HotChocolate GraphQL
    • SQL Sever

🏗️ Setup Instructions

1️⃣ Clone the repository

git clone https://github.com/artemshii/MiniBlogAPI.git
cd MiniBlogAPI

2️⃣ Configure the database connection

Create and edit your appsettings.json file:

"ConnectionStrings": {
  "DefaultConnection": "Your connection link"
}

3️⃣ Apply EF Core migrations

dotnet ef database update

4️⃣ Run the project

dotnet run

By default, the GraphQL Playground will be available at:
👉 https://localhost:5001/graphql


🧩 GraphQL API Examples

Below are example GraphQL queries, mutations, and subscriptions you can test directly in the Nitro Playground.


🔍 Queries

Get all users (offset and limit)

query {
  allUsers(offset: 1, limit: 11) {
    id
    userName
  }
}

Get all users (limit only)

query {
  allUsers(limit: 11) {
    id
    userName
  }
}

Get user by ID

query {
  usersById(id: 2) {
    id
    userName
  }
}

🧱 Mutations

Create a new user

mutation {
  createUser(_UserName: "John1092") {
    userName
  }
}

Like a post

mutation {
  like(_UserId: 1, _PostId: 1) {
    id
    dataStamp
    userId
    user {
      id
      userName
    }
    postId
    post {
      id
      dataStamp
      text
      publisherId
      publisher {
        userName
      }
    }
  }
}

🔔 Subscriptions

Subscribe to new posts from a specific user

subscription {
  onPostCreated(userId: 1) {
    id
    dataStamp
    text
  }
}

When a user with id = 1 creates a new post, subscribers will automatically receive it in real-time.


🗄️ Project Structure

MiniBlogAPI/
├── ApplicationDbContext.cs         # EF Core DB context
├── Controllers/                    # GraphQL queries, mutations, and subscriptions
├── Models/                         # Entity models (User, Post, Like)
├── Migrations/                     # EF Core migrations
├── Program.cs                      # App entry point
└── appsettings.json                # Configuration

⚙️ Technologies Used

  • **C# / .NET **
  • Entity Framework Core
  • HotChocolate GraphQL
  • SQL Server
  • Nitro Playground

About

Created MiniBlogAPI using ASP.NET, HotChocolate and GraphQL

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages