Skip to content

marcelmedina/vs-code-dev-days-api

Repository files navigation

Weather Forecast API

A modern, lightweight weather forecast API built with ASP.NET Core and .NET 9, providing simulated weather data for demonstration purposes.

📋 Overview

This project is a sample API that demonstrates best practices for creating RESTful services using ASP.NET Core minimal APIs with OpenAPI/Swagger documentation. It provides a single endpoint that returns a 5-day weather forecast with randomly generated temperatures and weather conditions.

✨ Features

  • Built on .NET 9 using ASP.NET Core minimal APIs
  • OpenAPI/Swagger documentation with custom configuration
  • CORS support for cross-origin requests
  • HTTP and HTTPS support
  • Clean, maintainable code structure
  • Example of record types in C#

🚀 Getting Started

Prerequisites

Running the API

Using the .NET CLI:

# Clone the repository
git clone https://github.com/yourusername/weather-forecast.git
cd weather-forecast

# Run the application
dotnet run

Using Visual Studio Code:

  1. Open the project folder in Visual Studio Code
  2. Make sure you have the C# Dev Kit extension installed
  3. Press F5 or use the Run and Debug view to start the application
  4. The Swagger UI will automatically open in your browser

API Endpoints

The API provides the following endpoint:

  • GET /api/weatherforecast
    • Returns a 5-day weather forecast
    • No authentication required
    • Response: Array of WeatherForecast objects

📖 API Documentation

When running in development mode, Swagger UI is available at:

The raw OpenAPI specification is available at:

📊 Data Model

The API returns WeatherForecast objects with the following properties:

Property Type Description
date string (date) The date of the forecast
temperatureC integer Temperature in Celsius
summary string Weather condition description (e.g., "Freezing", "Bracing", "Chilly", etc.)
temperatureF integer Temperature in Fahrenheit (calculated from Celsius)

Example response:

[
  {
    "date": "2023-10-15",
    "temperatureC": 14,
    "summary": "Bracing",
    "temperatureF": 57
  },
  {
    "date": "2023-10-16",
    "temperatureC": 7,
    "summary": "Cool",
    "temperatureF": 44
  }
]

🔧 Configuration

The application can be configured through the appsettings.json file and environment variables. Key configuration areas include:

  • HTTP/HTTPS Endpoints: Configured in Properties/launchSettings.json
  • CORS Policy: Configured in Program.cs
  • Swagger/OpenAPI: Customized in Program.cs

🧪 Testing

You can test the API using:

  1. Swagger UI: Available at /swagger when running in development mode
  2. curl:
    curl -X GET "https://localhost:7082/api/weatherforecast" -H "accept: application/json"
  3. Postman or similar API testing tools
  4. REST Client extension for VS Code

📚 Learn More

📄 License

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

🤝 Contact

For questions or support, please contact:


This README is for a sample project and may need modifications to match your specific implementation details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages