Skip to content

diegoperea20/Catalog-ASP.NET-10-Web-API-MongoDB

Repository files navigation

Catalog ASP.NET 10 Web API MongoDB

ASP.NET 10 Web API with MongoDB integration for catalog management.

Overview

This project provides a RESTful API for managing catalog items using ASP.NET Core and MongoDB. It includes CRUD operations, Docker containerization, and comprehensive API testing collections.

Tech Stack

  • .NET 10 - Web API framework
  • MongoDB - NoSQL database
  • Docker - Containerization
  • MongoDB.Driver - Official MongoDB C# driver

Getting Started

Prerequisites

  • .NET 10 SDK
  • Docker Desktop
  • PowerShell (for Windows)
  • Git

Installation

  1. Clone the repository:
git clone <repository-url>
cd Catalog
  1. Create the ASP.NET Web API project:
dotnet new webapi -n Catalog --use-controllers
  1. Install MongoDB driver:
dotnet add package MongoDB.Driver

Database Setup

Start MongoDB Container

docker run -d --rm --name mongo -p 27017:27017 -v mongodbdata:/data/db mongo

MongoDB Shell Commands

Access MongoDB container:

docker exec -it mongo bash

Open MongoDB shell:

mongosh

Database operations:

# List all databases
show dbs

# Switch to Catalog database
use Catalog

# List collections
show collections

# View all items with formatting
db.items.find().pretty()

Running the Application

Windows (PowerShell)

powershell -ExecutionPolicy Bypass -File .\run-with-env.ps1

Important: Ensure .gitignore is properly configured before running the script.

Cross-platform

dotnet run

API Documentation

The API provides the following endpoints:

Method Endpoint Description
GET /items Retrieve all items
GET /items/{id} Retrieve item by ID
POST /items Create new item
PUT /items/{id} Update existing item
DELETE /items/{id} Delete item by ID

API Testing Collections

The collections/ directory contains HTTP request files for testing the API using tools like Bruno or similar HTTP clients.

Available Collections

  • get all.yml - Retrieve all catalog items
  • get id item.yml - Retrieve specific item by ID
  • post item.yml - Create new catalog item
  • put id item.yml - Update existing item
  • delete id item.yml - Delete item by ID
  • opencollection.yml - Collection configuration file

Usage

  1. Import the collection files into your HTTP client
  2. Ensure the API is running on http://localhost:5195
  3. Execute requests to test API functionality

Project Structure

Catalog/
|-- README.md
|-- collections/          # API testing collections
|   |-- get all.yml
|   |-- get id item.yml
|   |-- post item.yml
|   |-- put id item.yml
|   |-- delete id item.yml
|   |-- opencollection.yml
|   |-- .gitignore
|-- Controllers/          # API controllers
|-- Models/              # Data models
|-- Services/            # Business logic
|-- appsettings.json     # Configuration
|-- run-with-env.ps1     # Windows execution script

Configuration

Update appsettings.json with your MongoDB connection string:

{
  "MongoDbSettings": {
    "ConnectionString": "mongodb://localhost:27017",
    "DatabaseName": "Catalog"
  }
}

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Submit a pull request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.


👨‍💻 Author / Autor

Diego Ivan Perea Montealegre


Created by Diego Ivan Perea Montealegre

About

ASP.NET 10 Web API with MongoDB integration for catalog management.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors