Skip to content

Commit

Permalink
Updated API URL and added versioning (dotnet#390)
Browse files Browse the repository at this point in the history
* Updated API URL and added versioning

The base URL for the API has been updated to a more simplified format. Additionally, versioning parameters have been added to all API calls to ensure compatibility with future updates. This includes changes in methods related to catalog items, brands, types and picture URI generation.

* Enhanced mobile-bff with additional references

The mobile-bff project has been updated to include references to the orderingApi and basketApi. Additionally, a launch profile name parameter has been added to the webhook client project setup.

* Refactored OIDC client setup and updated API endpoints

The OIDC client setup in the IdentityService has been refactored for better readability. Additional options have been added to disable certain validations and HTTPS requirement.

API endpoint URLs in OrderService have been updated to include versioning query parameters. This change ensures that the correct version of the API is called.

Localhost ports in SettingsViewModel have also been updated, reflecting changes in local development environment.

In appsettings.json, new routing configurations for catalog, ordering, and identity services have been added. These configurations include path matching rules and destination addresses.
  • Loading branch information
michaelstonis authored May 23, 2024
1 parent fd84893 commit 713da84
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 26 deletions.
12 changes: 6 additions & 6 deletions src/ClientApp/Services/Catalog/CatalogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace eShop.ClientApp.Services.Catalog;

public class CatalogService : ICatalogService
{
private const string ApiUrlBase = "api/v1/Catalog";
private const string ApiUrlBase = "api/catalog";
private readonly IFixUriService _fixUriService;
private readonly IRequestProvider _requestProvider;
private readonly ISettingsService _settingsService;
Expand All @@ -24,7 +24,7 @@ public CatalogService(ISettingsService settingsService, IRequestProvider request
public async Task<IEnumerable<CatalogItem>> FilterAsync(int catalogBrandId, int catalogTypeId)
{
var uri = UriHelper.CombineUri(_settingsService.GatewayCatalogEndpointBase,
$"{ApiUrlBase}/items/type/{catalogTypeId}/brand/{catalogBrandId}");
$"{ApiUrlBase}/items/type/{catalogTypeId}/brand/{catalogBrandId}?PageSize=100&PageIndex=0&api-version=1.0");

var catalog = await _requestProvider.GetAsync<CatalogRoot>(uri).ConfigureAwait(false);

Expand All @@ -33,7 +33,7 @@ public async Task<IEnumerable<CatalogItem>> FilterAsync(int catalogBrandId, int

public async Task<IEnumerable<CatalogItem>> GetCatalogAsync()
{
var uri = UriHelper.CombineUri(_settingsService.GatewayCatalogEndpointBase, $"{ApiUrlBase}/items?PageSize=100");
var uri = UriHelper.CombineUri(_settingsService.GatewayCatalogEndpointBase, $"{ApiUrlBase}/items?PageSize=100&api-version=1.0");

var catalog = await _requestProvider.GetAsync<CatalogRoot>(uri).ConfigureAwait(false);

Expand All @@ -49,7 +49,7 @@ public async Task<IEnumerable<CatalogItem>> GetCatalogAsync()
public async Task<CatalogItem> GetCatalogItemAsync(int catalogItemId)
{
var uri = UriHelper.CombineUri(_settingsService.GatewayCatalogEndpointBase,
$"{ApiUrlBase}/items/{catalogItemId}");
$"{ApiUrlBase}/items/{catalogItemId}?api-version=1.0");

var catalogItem = await _requestProvider.GetAsync<CatalogItem>(uri).ConfigureAwait(false);

Expand All @@ -64,7 +64,7 @@ public async Task<CatalogItem> GetCatalogItemAsync(int catalogItemId)

public async Task<IEnumerable<CatalogBrand>> GetCatalogBrandAsync()
{
var uri = UriHelper.CombineUri(_settingsService.GatewayCatalogEndpointBase, $"{ApiUrlBase}/catalogbrands");
var uri = UriHelper.CombineUri(_settingsService.GatewayCatalogEndpointBase, $"{ApiUrlBase}/catalogbrands?api-version=1.0");

var brands = await _requestProvider.GetAsync<IEnumerable<CatalogBrand>>(uri).ConfigureAwait(false);

Expand All @@ -73,7 +73,7 @@ public async Task<IEnumerable<CatalogBrand>> GetCatalogBrandAsync()

public async Task<IEnumerable<CatalogType>> GetCatalogTypeAsync()
{
var uri = UriHelper.CombineUri(_settingsService.GatewayCatalogEndpointBase, $"{ApiUrlBase}/catalogtypes");
var uri = UriHelper.CombineUri(_settingsService.GatewayCatalogEndpointBase, $"{ApiUrlBase}/catalogtypes?api-version=1.0");

var types = await _requestProvider.GetAsync<IEnumerable<CatalogType>>(uri).ConfigureAwait(false);

Expand Down
2 changes: 1 addition & 1 deletion src/ClientApp/Services/FixUri/FixUriService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void FixCatalogItemPictureUri(IEnumerable<CatalogItem> catalogItems)
{
foreach (var catalogItem in catalogItems)
{
catalogItem.PictureUri = Path.Combine(_settingsService.GatewayCatalogEndpointBase, $"api/v1/catalog/items/{catalogItem.Id}/pic");
catalogItem.PictureUri = Path.Combine(_settingsService.GatewayCatalogEndpointBase, $"api/catalog/items/{catalogItem.Id}/pic?api-version=1.0");
}
}
}
Expand Down
29 changes: 18 additions & 11 deletions src/ClientApp/Services/Identity/IdentityService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,23 @@ await _settingsService

private OidcClient GetClient()
{
return new OidcClient(
new OidcClientOptions
{
Authority = _settingsService.IdentityEndpointBase,
ClientId = _settingsService.ClientId,
ClientSecret = _settingsService.ClientSecret,
Scope = "openid profile basket orders offline_access",
RedirectUri = _settingsService.CallbackUri,
PostLogoutRedirectUri = _settingsService.CallbackUri,
Browser = _browser
});
var options = new OidcClientOptions
{
Authority = _settingsService.IdentityEndpointBase,
ClientId = _settingsService.ClientId,
ClientSecret = _settingsService.ClientSecret,
Scope = "openid profile basket orders offline_access",
RedirectUri = _settingsService.CallbackUri,
PostLogoutRedirectUri = _settingsService.CallbackUri,
RefreshDiscoveryDocumentForLogin = false,
RefreshDiscoveryOnSignatureFailure = false,
Browser = _browser,
};

options.Policy.Discovery.RequireHttps = false;
options.Policy.Discovery.ValidateEndpoints = false;
options.Policy.Discovery.ValidateIssuerName = false;

return new OidcClient(options);
}
}
10 changes: 5 additions & 5 deletions src/ClientApp/Services/Order/OrderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace eShop.ClientApp.Services.Order;

public class OrderService : IOrderService
{
private const string ApiUrlBase = "/api/v1/orders";
private const string ApiUrlBase = "api/orders";
private readonly IIdentityService _identityService;
private readonly IRequestProvider _requestProvider;
private readonly ISettingsService _settingsService;
Expand All @@ -32,7 +32,7 @@ public async Task CreateOrderAsync(Models.Orders.Order newOrder)
return;
}

var uri = UriHelper.CombineUri(_settingsService.GatewayOrdersEndpointBase, ApiUrlBase);
var uri = $"{UriHelper.CombineUri(_settingsService.GatewayOrdersEndpointBase, ApiUrlBase)}?api-version=1.0";

var success = await _requestProvider.PostAsync(uri, newOrder, authToken, "x-requestid").ConfigureAwait(false);
}
Expand All @@ -46,7 +46,7 @@ public async Task CreateOrderAsync(Models.Orders.Order newOrder)
return Enumerable.Empty<Models.Orders.Order>();
}

var uri = UriHelper.CombineUri(_settingsService.GatewayOrdersEndpointBase, ApiUrlBase);
var uri = $"{UriHelper.CombineUri(_settingsService.GatewayOrdersEndpointBase, ApiUrlBase)}?api-version=1.0";

var orders =
await _requestProvider.GetAsync<IEnumerable<Models.Orders.Order>>(uri, authToken).ConfigureAwait(false);
Expand All @@ -65,7 +65,7 @@ public async Task CreateOrderAsync(Models.Orders.Order newOrder)

try
{
var uri = UriHelper.CombineUri(_settingsService.GatewayOrdersEndpointBase, $"{ApiUrlBase}/{orderId}");
var uri = $"{UriHelper.CombineUri(_settingsService.GatewayOrdersEndpointBase, $"{ApiUrlBase}/{orderId}")}?api-version=1.0";

var order =
await _requestProvider.GetAsync<Models.Orders.Order>(uri, authToken).ConfigureAwait(false);
Expand All @@ -87,7 +87,7 @@ public async Task<bool> CancelOrderAsync(int orderId)
return false;
}

var uri = UriHelper.CombineUri(_settingsService.GatewayOrdersEndpointBase, $"{ApiUrlBase}/cancel");
var uri = $"{UriHelper.CombineUri(_settingsService.GatewayOrdersEndpointBase, $"{ApiUrlBase}/cancel")}?api-version=1.0";

var cancelOrderCommand = new CancelOrderCommand(orderId);

Expand Down
4 changes: 2 additions & 2 deletions src/ClientApp/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public SettingsViewModel(
GatewayCatalogEndpoint =
!string.IsNullOrEmpty(_settingsService.GatewayCatalogEndpointBase)
? _settingsService.GatewayCatalogEndpointBase
: "http://localhost:5222";
: "http://localhost:11632";

GatewayBasketEndpoint =
!string.IsNullOrEmpty(_settingsService.GatewayBasketEndpointBase)
Expand All @@ -62,7 +62,7 @@ public SettingsViewModel(
GatewayOrdersEndpoint =
!string.IsNullOrEmpty(_settingsService.GatewayOrdersEndpointBase)
? _settingsService.GatewayOrdersEndpointBase
: "http://localhost:5224";
: "http://localhost:11632";

ToggleMockServicesCommand = new RelayCommand(ToggleMockServices);

Expand Down
51 changes: 51 additions & 0 deletions src/Mobile.Bff.Shopping/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,43 @@
"PathRemovePrefix": "/catalog-api"
}
]
},
"catalog": {
"ClusterId": "catalog",
"Match": {
"Path": "/api/catalog/{*any}",
"QueryParameters": [
{
"Name": "api-version",
"Values": [ "1.0", "1" ],
"Mode": "Exact"
}
]
}
},
"ordering": {
"ClusterId": "orders",
"Match": {
"Path": "/api/orders/{*any}",
"QueryParameters": [
{
"Name": "api-version",
"Values": [ "1.0", "1" ],
"Mode": "Exact"
}
]
}
},
"identity": {
"ClusterId": "identity",
"Match": {
"Path": "/identity/{*any}"
},
"Transforms": [
{
"PathRemovePrefix": "/identity"
}
]
}
},

Expand All @@ -199,6 +236,20 @@
"Address": "http://catalog-api"
}
}
},
"orders": {
"Destinations": {
"orderDestination": {
"Address": "http://ordering-api"
}
}
},
"identity": {
"Destinations": {
"orderDestination": {
"Address": "http://localhost:5223"
}
}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/eShop.AppHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@
// Reverse proxies
builder.AddProject<Projects.Mobile_Bff_Shopping>("mobile-bff")
.WithReference(catalogApi)
.WithReference(orderingApi)
.WithReference(basketApi)
.WithReference(identityApi);

// Apps
var webhooksClient = builder.AddProject<Projects.WebhookClient>("webhooksclient")
var webhooksClient = builder.AddProject<Projects.WebhookClient>("webhooksclient", launchProfileName)
.WithReference(webHooksApi)
.WithEnvironment("IdentityUrl", identityEndpoint);

Expand Down

0 comments on commit 713da84

Please sign in to comment.