Skip to content

This repository contains a complete case study project demonstrating how to develop an ASP.NET Core Web API for crawling product data from Trendyol and transforming the retrieved product information using AI.

Notifications You must be signed in to change notification settings

bilalsengul/ASP.NET-Core-Web-API-AI-Integration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Trendyol Product AI Integration

A modern web application that crawls product information from Trendyol, transforms it using AI, and allows you to save and manage your product collection.

Features

  • Product Crawling: Easily fetch product details from Trendyol URLs
  • AI Transformation: Transform product information using OpenAI's GPT-4
  • Product Management: Save and view your transformed products
  • Modern UI: Clean and responsive interface built with Material-UI
  • Multi-language Support: Product details are translated to English

Prerequisites

Project Structure

TrendyolProductAPI/          # Backend API project
├── Controllers/            # API endpoints
├── Models/                # Data models
├── Services/              # Business logic
├── Middleware/           # Custom middleware
└── Extensions/           # Extension methods

frontend/                  # React frontend
├── src/
│   ├── components/      # React components
│   ├── services/       # API integration
│   └── App.tsx        # Main application

Installation

1. Clone the Repository

git clone <repository-url>
cd <repository-name>

2. Backend Setup

  1. Navigate to the API project:
cd TrendyolProductAPI
  1. Verify .NET version:
dotnet --version
# Should show 9.0.x
  1. Install dependencies:
dotnet restore
  1. Configure API Keys: Create or update appsettings.json:
{
  "ApiKey": "your-api-key",
  "OpenAI": {
    "ApiKey": "your-openai-api-key",
    "Model": "gpt-4-1106-preview"
  }
}

3. Frontend Setup

  1. Navigate to the frontend directory:
cd frontend
  1. Install dependencies:
npm install
  1. Update API configuration: In src/services/api.ts, update the API key and base URL if needed.

Running the Application

Start the Backend

cd TrendyolProductAPI
dotnet run

The API will be available at http://localhost:5121

Start the Frontend

cd frontend
npm run dev

The application will be available at http://localhost:5173

Usage Guide

1. Adding Products

  1. Click "Add New Product" or navigate to the Crawl page
  2. Enter a Trendyol product URL (e.g., https://www.trendyol.com/brand/product-p-123456)
  3. Click "Crawl Product"

2. Transforming Products

  1. After crawling, you'll see the product details
  2. Click "Transform Product"
  3. The AI will:
    • Translate to English
    • Generate a description
    • Assign a quality score

3. Managing Products

  • Save transformed products
  • View all products in the list
  • Sort by AI score
  • View detailed information

API Documentation

Endpoints

POST /api/Product/crawl
- Body: Product URL
- Header: X-API-Key

POST /api/Product/transform/{sku}
- Path: SKU
- Header: X-API-Key

POST /api/Product/save
- Body: Product object
- Header: X-API-Key

GET /api/Product
- Header: X-API-Key

GET /api/Product/{sku}
- Path: SKU
- Header: X-API-Key

Dependencies

Backend (.NET 9.0)

  • HtmlAgilityPack (1.11.54)
  • OpenAI (1.7.2)
  • Microsoft.AspNetCore.OpenApi (9.0.0)
  • Swashbuckle.AspNetCore (6.5.0)

Frontend

  • React 18
  • Material-UI
  • React Router
  • Axios

Development

Backend Development

cd TrendyolProductAPI
dotnet watch run

Frontend Development

cd frontend
npm run dev

Error Handling

The application includes comprehensive error handling for:

  • Invalid URLs
  • Network issues
  • API rate limits
  • Missing products
  • Authentication errors

Security

  • API Key authentication required for all endpoints
  • OpenAI API key stored securely in backend
  • CORS configured for frontend access
  • Request/Response logging
  • Input validation

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

License

This project is licensed under the MIT License.

API Keys

The application requires two API keys to function:

  1. Application API Key: Used for authenticating requests between the frontend and backend

    • Set this in TrendyolProductAPI/appsettings.json as ApiKey
    • Set the same key in frontend/src/services/api.ts as API_KEY
  2. OpenAI API Key: Used for AI-powered product transformations

    • Set this in TrendyolProductAPI/appsettings.json under OpenAI:ApiKey

For security:

  • Never commit real API keys to version control
  • Use the sample configuration file (appsettings.sample.json) as a template
  • Keep your API keys secure and rotate them regularly

About

This repository contains a complete case study project demonstrating how to develop an ASP.NET Core Web API for crawling product data from Trendyol and transforming the retrieved product information using AI.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •