updated Microser (gateway)

This commit is contained in:
M. Akif Tokatlioglu
2024-03-31 10:10:36 +03:00
parent 7c19b96d81
commit 2f2a39584d
22 changed files with 267 additions and 24 deletions

View File

@@ -16,7 +16,8 @@ public class WeatherForecastApiService : IWeatherForecastApiService
public async Task<WeatherForecast[]?> GetAllAsync()
{
var httpClient = _httpClientFactory.CreateClient("WeatherForecastAPIClient");
// get from gateway
var httpClient = _httpClientFactory.CreateClient("APIGateway");
var request = new HttpRequestMessage(
HttpMethod.Get,
"/WeatherForecast");
@@ -24,6 +25,15 @@ public class WeatherForecastApiService : IWeatherForecastApiService
.ConfigureAwait(false);
response.EnsureSuccessStatusCode();
//// directly from API
//var httpClient = _httpClientFactory.CreateClient("WeatherForecastAPIClient");
//var request = new HttpRequestMessage(
// HttpMethod.Get,
// "/api/WeatherForecast");
//var response = await httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead)
// .ConfigureAwait(false);
//response.EnsureSuccessStatusCode();
//var content = await response.Content.ReadAsStringAsync();
//var weatherForecastList = JsonSerializer.Deserialize<List<WeatherForecast>>(content);
@@ -74,7 +84,7 @@ public class WeatherForecastApiService : IWeatherForecastApiService
public async Task<WeatherForecast?> GetByIdAsync(int id)
{
var httpClient = _httpClientFactory.CreateClient("WeatherForecastAPIClient");
var httpClient = _httpClientFactory.CreateClient("APIGateway");
var request = new HttpRequestMessage(
HttpMethod.Get,
"/WeatherForecast/" + id);
@@ -87,7 +97,7 @@ public class WeatherForecastApiService : IWeatherForecastApiService
public async Task<WeatherForecast?> AddAsync(WeatherForecast weatherForecast)
{
var httpClient = _httpClientFactory.CreateClient("WeatherForecastAPIClient");
var httpClient = _httpClientFactory.CreateClient("APIGateway");
var request = new HttpRequestMessage(
HttpMethod.Post, "/WeatherForecast")
{
@@ -104,7 +114,7 @@ public class WeatherForecastApiService : IWeatherForecastApiService
public async Task<bool> DeleteByIdAsync(int id)
{
var httpClient = _httpClientFactory.CreateClient("WeatherForecastAPIClient");
var httpClient = _httpClientFactory.CreateClient("APIGateway");
var request = new HttpRequestMessage(
HttpMethod.Delete, "/WeatherForecast/" + id.ToString());
@@ -124,7 +134,7 @@ public class WeatherForecastApiService : IWeatherForecastApiService
public async Task<bool> UpdateAsync(int id, WeatherForecast weatherForecast)
{
var httpClient = _httpClientFactory.CreateClient("WeatherForecastAPIClient");
var httpClient = _httpClientFactory.CreateClient("APIGateway");
var request = new HttpRequestMessage(
HttpMethod.Put, "/WeatherForecast/" + weatherForecast.Id.ToString())
{