Sa herkese ben chatgpt ye api kodlatmak istiyorum bu mümkün mü nasıl yapabilirim hava durumu apisi gibi ama veri çekmeden yani ?
orda kimse yok mu yardımcı olacak
orda kimse yok mu yardımcı olacak
Follow along with the video below to see how to install our site as a web app on your home screen.
Not: This feature may not be available in some browsers.
gerçek veriler istiyorsan mecbur dışa bağımlı olmak zorundasın ama sadece benzesin istiyorsan;Sa herkese ben chatgpt ye api kodlatmak istiyorum bu mümkün mü nasıl yapabilirim hava durumu apisi gibi ama veri çekmeden yani ?
orda kimse yok mu yardımcı olacak
using Microsoft.AspNetCore.Mvc;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
app.UseSwagger();
app.UseSwaggerUI();
Random rnd = new Random();
// Şehir listesi ve rastgele oluşturulan durumlar
string[] conditions = new[] { "Sunny", "Cloudy", "Rainy", "Windy", "Storm", "Snow" };
// /api/weather?city=Istanbul
app.MapGet("/api/weather", (string city) =>
{
var result = new
{
City = city,
Temperature = rnd.Next(-5, 40), // -5 ile 40 derece arasında
Humidity = rnd.Next(10, 90), // %
WindSpeed = rnd.Next(1, 20), // m/s
Condition = conditions[rnd.Next(conditions.Length)],
UpdatedAt = DateTime.Now
};
return Results.Ok(result);
});
app.Run();
{
"city": "Ankara",
"temperature": 17,
"humidity": 48,
"windspeed": 6,
"condition": "Sunny",
"updatedAt": "2025-12-05T10:32:41.583Z"
}
var weatherDatabase = new Dictionary<string, object>
{
{ "Istanbul", new { Temperature = 15, Humidity = 60, Condition = "Cloudy" } },
{ "Ankara", new { Temperature = 10, Humidity = 55, Condition = "Sunny" } },
{ "Izmir", new { Temperature = 18, Humidity = 50, Condition = "Rainy" } },
};
app.MapGet("/api/weather", (string city) =>
{
if (weatherDatabase.ContainsKey(city))
{
return Results.Ok(weatherDatabase[city]);
}
return Results.NotFound(new { error = "City not found" });
});
hocam peki api klonlatabilir miyim sadece urlden api anahtarı vs olmadan ?gerçek veriler istiyorsan mecbur dışa bağımlı olmak zorundasın ama sadece benzesin istiyorsan;
Net Core üzerinde bir önerisi var GPT 'nin diyor ki ;
1) Proje Oluştur
new webapi -n FakeWeatherApi
2) Program.cs içeriği
Aşağıdaki kod rastgele hava durumu üretir; sen belirli şehirler için sabit değerler de verebilirsin:
C#:using Microsoft.AspNetCore.Mvc; var builder = WebApplication.CreateBuilder(args); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); var app = builder.Build(); app.UseSwagger(); app.UseSwaggerUI(); Random rnd = new Random(); // Şehir listesi ve rastgele oluşturulan durumlar string[] conditions = new[] { "Sunny", "Cloudy", "Rainy", "Windy", "Storm", "Snow" }; // /api/weather?city=Istanbul app.MapGet("/api/weather", (string city) => { var result = new { City = city, Temperature = rnd.Next(-5, 40), // -5 ile 40 derece arasında Humidity = rnd.Next(10, 90), // % WindSpeed = rnd.Next(1, 20), // m/s Condition = conditions[rnd.Next(conditions.Length)], UpdatedAt = DateTime.Now }; return Results.Ok(result); }); app.Run();
✔ Örnek Çıktı
GET http://localhost:5000/api/weather?city=Ankara
Kod:{ "city": "Ankara", "temperature": 17, "humidity": 48, "windspeed": 6, "condition": "Sunny", "updatedAt": "2025-12-05T10:32:41.583Z" }
🌤 Alternatif: Şehirlere sabit veri döndüren versiyon
Gerçek gibi ama sabit veri döndürmesini istiyorsan:
C#:var weatherDatabase = new Dictionary<string, object> { { "Istanbul", new { Temperature = 15, Humidity = 60, Condition = "Cloudy" } }, { "Ankara", new { Temperature = 10, Humidity = 55, Condition = "Sunny" } }, { "Izmir", new { Temperature = 18, Humidity = 50, Condition = "Rainy" } }, }; app.MapGet("/api/weather", (string city) => { if (weatherDatabase.ContainsKey(city)) { return Results.Ok(weatherDatabase[city]); } return Results.NotFound(new { error = "City not found" }); });
hocam prompt ile olur dimi benim asıl derdim api klonlamak dagerçek veriler istiyorsan mecbur dışa bağımlı olmak zorundasın ama sadece benzesin istiyorsan;
Net Core üzerinde bir önerisi var GPT 'nin diyor ki ;
1) Proje Oluştur
new webapi -n FakeWeatherApi
2) Program.cs içeriği
Aşağıdaki kod rastgele hava durumu üretir; sen belirli şehirler için sabit değerler de verebilirsin:
C#:using Microsoft.AspNetCore.Mvc; var builder = WebApplication.CreateBuilder(args); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); var app = builder.Build(); app.UseSwagger(); app.UseSwaggerUI(); Random rnd = new Random(); // Şehir listesi ve rastgele oluşturulan durumlar string[] conditions = new[] { "Sunny", "Cloudy", "Rainy", "Windy", "Storm", "Snow" }; // /api/weather?city=Istanbul app.MapGet("/api/weather", (string city) => { var result = new { City = city, Temperature = rnd.Next(-5, 40), // -5 ile 40 derece arasında Humidity = rnd.Next(10, 90), // % WindSpeed = rnd.Next(1, 20), // m/s Condition = conditions[rnd.Next(conditions.Length)], UpdatedAt = DateTime.Now }; return Results.Ok(result); }); app.Run();
✔ Örnek Çıktı
GET http://localhost:5000/api/weather?city=Ankara
Kod:{ "city": "Ankara", "temperature": 17, "humidity": 48, "windspeed": 6, "condition": "Sunny", "updatedAt": "2025-12-05T10:32:41.583Z" }
🌤 Alternatif: Şehirlere sabit veri döndüren versiyon
Gerçek gibi ama sabit veri döndürmesini istiyorsan:
C#:var weatherDatabase = new Dictionary<string, object> { { "Istanbul", new { Temperature = 15, Humidity = 60, Condition = "Cloudy" } }, { "Ankara", new { Temperature = 10, Humidity = 55, Condition = "Sunny" } }, { "Izmir", new { Temperature = 18, Humidity = 50, Condition = "Rainy" } }, }; app.MapGet("/api/weather", (string city) => { if (weatherDatabase.ContainsKey(city)) { return Results.Ok(weatherDatabase[city]); } return Results.NotFound(new { error = "City not found" }); });
o zaman öyle desene kardeşim ona göre araştırma yapardıkhocam prompt ile olur dimi benim asıl derdim api klonlamak da![]()