File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed
src/microservices/Demo.Microservices.Orders.API/Services Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change 2929 key : AZURESTORAGE_CONNECTIONSTRING
3030 - name : SHIPMENTS_API_URI
3131 value : http://contoso-microservices-shipments-internal-service:88/api/v1/shipments
32+ - name : SHIPMENTS_API_KEY
33+ valueFrom :
34+ secretKeyRef :
35+ name : orders-secrets
36+ key : SHIPMENTS_API_KEY
3237 livenessProbe :
3338 httpGet :
3439 path : /api/v1/health
@@ -66,4 +71,5 @@ metadata:
6671 app : contoso
6772 microservice : orders
6873data :
69- AZURESTORAGE_CONNECTIONSTRING : <base64 encoded connection string>
74+ AZURESTORAGE_CONNECTIONSTRING : <base64 encoded connection string>
75+ SHIPMENTS_API_KEY : <APIM API key>
Original file line number Diff line number Diff line change @@ -23,11 +23,18 @@ public ShipmentService(IConfiguration configuration)
2323 public async Task < ShipmentInformation > CreateAsync ( Address address )
2424 {
2525 var shipmentBaseUri = _configuration [ "SHIPMENTS_API_URI" ] ;
26-
26+ var request = new HttpRequestMessage ( HttpMethod . Post , shipmentBaseUri ) ;
27+
2728 var rawBody = JsonConvert . SerializeObject ( address ) ;
28- var postBody = new StringContent ( rawBody , Encoding . UTF8 , "application/json" ) ;
29+ request . Content = new StringContent ( rawBody , Encoding . UTF8 , "application/json" ) ;
30+
31+ var shipmentApiKey = _configuration [ "SHIPMENTS_API_KEY" ] ;
32+ if ( ! string . IsNullOrWhiteSpace ( shipmentApiKey ) )
33+ {
34+ request . Headers . Add ( "API-Key" , shipmentApiKey ) ;
35+ }
2936
30- var response = await _httpClient . PostAsync ( shipmentBaseUri , postBody ) ;
37+ var response = await _httpClient . SendAsync ( request ) ;
3138 if ( response . StatusCode != HttpStatusCode . Created )
3239 {
3340 throw new Exception ( "Unable to initiate a shipment" ) ;
You can’t perform that action at this time.
0 commit comments