Skip to content

Commit 8187efb

Browse files
committed
- Update Request/Response Headers
1 parent d0a323c commit 8187efb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+409
-178
lines changed

ApiAggregator.sln renamed to ApiAggregator.Net.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ VisualStudioVersion = 17.9.34723.18
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{4338FF70-3C81-4370-ACFB-00E14545BA99}"
77
EndProject
8-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApiAggregator.Net", "src\ApiAggregator\ApiAggregator.Net.csproj", "{8250784C-5415-47C2-9FE4-9E54FA4672B6}"
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApiAggregator", "src\ApiAggregator\ApiAggregator.csproj", "{8250784C-5415-47C2-9FE4-9E54FA4672B6}"
99
EndProject
1010
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{31E7A02C-167D-46FB-A90A-F3995FD5682D}"
1111
EndProject

README.md

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# <img src="https://github.com/CodeShayk/ApiAggregator/blob/master/Images/ninja-icon-16.png" alt="ninja" style="width:30px;"/> ApiAggregator.Net v1.0
1+
# <img src="https://github.com/CodeShayk/ApiAggregator/blob/master/Images/ninja-icon-16.png" alt="ninja" style="width:30px;"/> ApiAggregator v1.0
22
[![NuGet version](https://badge.fury.io/nu/ApiAggregator.svg)](https://badge.fury.io/nu/ApiAggregator) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/CodeShayk/ApiAggregator/blob/master/LICENSE.md)
33
[![Master-Build](https://github.com/CodeShayk/ApiAggregator/actions/workflows/Master-Build.yml/badge.svg)](https://github.com/CodeShayk/ApiAggregator/actions/workflows/Master-Build.yml)
44
[![GitHub Release](https://img.shields.io/github/v/release/CodeShayk/ApiAggregator?logo=github&sort=semver)](https://github.com/CodeShayk/ApiAggregator/releases/latest)
@@ -83,12 +83,13 @@ As mentioned previously, You can configure an api in `Parent` or `Child` (nested
8383
To create `Web Api` defined as `parent` or `nested` api, you need to implement from `WebApi<TResult>` class,
8484
where `TResult` is `IApiResult` interface (or `ApiResult` base class) implementation and is the result that will be returned from executing the api.
8585

86-
Upon creating the web api class, you need to provide `GetUrl()` method implementation.
87-
* Implement the `GetUrl(IRequestContext context, IApiResult parentApiResult)` method to return the constructed endpoint based on given parameters of the method.
86+
Upon creating the web api class, you need to provide `GetUrl()` method implementation to return `Uri` instance.
87+
* Implement the `GetUrl(IRequestContext context, IApiResult parentApiResult)` method to return the constructed endpoint using given parameters of the method.
8888
* For `Parent Api`, only `IRequestContext` context parameter is passed to GetUrl() method to resolve the Url endpoint.
8989
* For `Nested Api`, api result parameter (ie. `IApiResult` parentApiResult) from the parent api is additionally passed in to GetUrl() method along with IRequestContext context parameter.
90-
* Optionally, override `GetHeaders()` method to provide any list of `request headers` for the api.
91-
* `IApiResult` implementation exposes `Headers` property for any `response headers` received as part of the api response.
90+
* Optionally, override `GetRequestHeaders()` method to provide a dictionary of `outgoing headers` for the api request.
91+
* Optionally, override `GetResponseHeaders()` method to provide any list of `incoming headers` from the api response.
92+
* `IApiResult` implementation exposes `Headers` property for subscribed `response headers` received as part of the api response.
9293

9394
`Important:`
9495
- The api `endpoint` needs to be resolved before executing the api with `ApiEngine`.
@@ -104,12 +105,28 @@ public class CustomerApi : WebApi<CustomerResult>
104105
{
105106
}
106107
108+
// Override to construct the api endpoint.
107109
protected override Uri GetUrl(IRequestContext context, IApiResult parentApiResult)
108110
{
109111
// Executes as root or level 1 api. parentApiResult should be null.
110112
var customerContext = (CustomerContext)context;
111113
112-
return new Uri(string.Format(Endpoints.BaseAddress + Endpoints.Customer, customerContext.CustomerId));
114+
return new Uri(string.Format(Endpoints.Customer, customerContext.CustomerId));
115+
}
116+
117+
// Override to pass custom outgoing headers with the api request.
118+
protected override IDictionary<string, string> GetRequestHeaders()
119+
{
120+
return new Dictionary<string, string>
121+
{
122+
{ "x-meta-branch-code", "Geneva" }
123+
};
124+
}
125+
126+
// Override to get custom incoming headers with the api response.
127+
protected override IEnumerable<string> GetResponseHeaders()
128+
{
129+
return new[] { "x-meta-branch-code" };
113130
}
114131
}
115132
```
@@ -125,7 +142,7 @@ internal class CommunicationApi : WebApi<CommunicationResult>
125142
protected override Uri GetUrl(IRequestContext context, IApiResult parentApiResult)
126143
{
127144
var customer = (CustomerResult)parentApiResult;
128-
return new Uri(string.Format(Endpoints.BaseAddress + Endpoints.Communication, customer.Id));
145+
return new Uri(string.Format(Endpoints.Communication, customer.Id));
129146
}
130147
}
131148
```

src/ApiAggregator/ApiAggregate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace ApiAggregator.Net
1+
namespace ApiAggregator
22
{
33
/// <summary>
44
/// Implement the api aggregate with web apis and result transformers to map data to aggregated contract.

src/ApiAggregator/ApiAggregator.Net.csproj renamed to src/ApiAggregator/ApiAggregator.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@
2020
</PropertyGroup>
2121

2222
<ItemGroup>
23-
<None Include="..\..\Images\ninja-icon-16.png" Link="misc\ninja-icon-16.png">
23+
<None Include="..\..\Images\ninja-icon-16.png" Link="Misc\ninja-icon-16.png">
2424
<Pack>True</Pack>
2525
<PackagePath>\</PackagePath>
2626
</None>
27-
<None Include="..\..\LICENSE" Link="misc\LICENSE">
27+
<None Include="..\..\LICENSE" Link="Misc\LICENSE">
2828
<Pack>True</Pack>
2929
<PackagePath>\</PackagePath>
3030
</None>
31-
<None Include="..\..\README.md" Link="misc\README.md">
31+
<None Include="..\..\README.md" Link="Misc\README.md">
3232
<Pack>True</Pack>
3333
<PackagePath>\</PackagePath>
3434
</None>
@@ -39,7 +39,7 @@
3939
</ItemGroup>
4040

4141
<ItemGroup>
42-
<Folder Include="misc\" />
42+
<Folder Include="Misc\" />
4343
</ItemGroup>
4444

4545
</Project>

src/ApiAggregator/ApiComparer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace ApiAggregator.Net
1+
namespace ApiAggregator
22
{
33
internal class ApiComparer : IEqualityComparer<IWebApi>
44
{

src/ApiAggregator/ApiList.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace ApiAggregator.Net
1+
namespace ApiAggregator
22
{
33
internal class ApiList : IApiList
44
{

src/ApiAggregator/ApiResult.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
namespace ApiAggregator.Net
1+
namespace ApiAggregator
22
{
33
public abstract class ApiResult : IApiResult
44
{
55
public ApiResult()
66
{
7-
Headers = [];
7+
Headers = new Dictionary<string, string>();
88
}
99

10-
public List<KeyValuePair<string, string>> Headers { get; set; }
10+
public IDictionary<string, string> Headers { get; set; }
1111
}
1212
}

src/ApiAggregator/CacheResultAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace ApiAggregator.Net
1+
namespace ApiAggregator
22
{
33
public class CacheResultAttribute : Attribute
44
{ }
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
namespace ApiAggregator.Net
1+
namespace ApiAggregator
22
{
33
public class CollectionResult<T> : List<T>, IApiResult
44
{
55
public CollectionResult(IEnumerable<T> list) : base(list)
66
{
7-
Headers = [];
7+
Headers = new Dictionary<string, string>();
88
}
99

10-
public List<KeyValuePair<string, string>> Headers { get; set; }
10+
public IDictionary<string, string> Headers { get; set; }
1111
}
1212
}

src/ApiAggregator/CreateAggregate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace ApiAggregator.Net
1+
namespace ApiAggregator
22
{
33
#region Helpers
44

0 commit comments

Comments
 (0)