@@ -11,9 +11,9 @@ Flying Proxy aims to:
1111- Better performance
1212- Maintainability
1313
14- ### Sample Client (Web)
14+ ## Sample Client (Web)
1515
16- #### Add ProxySettings section to the appsettings.json
16+ ### Add ProxySettings section to the appsettings.json
1717``` json
1818"ProxySettings" : {
1919 "RegionKeys" : {
@@ -24,7 +24,7 @@ Flying Proxy aims to:
2424}
2525```
2626
27- #### APIs Definitions
27+ ### APIs Definitions
2828``` csharp
2929// This API expose methods from localhost:5000 and localhost:5001 as configured on ProxySettings
3030 [ApiRoute (" api/[controller]" , regionKey : " Main" )]
@@ -49,6 +49,12 @@ public interface IGuidelineApi : IApiContract
4949 [HttpPostMarker ]
5050 Task TaskActionPost (ComplexTypeModel model );
5151
52+ [HttpPostMarker (ContentType = ContentType .MultipartFormData )]
53+ Task TaskActionBarMultipartFormData (Bar model );
54+
55+ [HttpPostMarker (ContentType = ContentType .Xml )]
56+ Task TaskActionBarSimpleXml (BarSimple model );
57+
5258 /// <summary >
5359 /// Template and parameter usage, key parameter will be part of the request Url
5460 /// and extracting it as api/guideline/kv/<key >
@@ -61,7 +67,7 @@ public interface IGuidelineApi : IApiContract
6167}
6268```
6369
64- #### Startup ConfigureServices
70+ ### Startup ConfigureServices
6571``` csharp
6672public void ConfigureServices (IServiceCollection services )
6773{
@@ -76,9 +82,9 @@ public void ConfigureServices(IServiceCollection services)
7682}
7783```
7884
79- #### Proxy Usage (DI)
85+ ### Proxy Usage (DI)
8086``` csharp
81- public class TestController : Controller
87+ public class HomeController : Controller
8288{
8389 private readonly IGuidelineApi _api ;
8490
@@ -87,96 +93,42 @@ public class TestController : Controller
8793 _api = api ;
8894 }
8995
90- public async Task <IActionResult > GetPostsAsync ()
96+ public async Task <IEnumerable < SampleModel >> GetModels ()
9197 {
92- var items = await _api .GetPostsAsync ();
93- return Json ( items ) ;
98+ var items = await _api .GetEnumerableModels ();
99+ return items ;
94100 }
95101}
96102```
97103
98- ### Backend - Server Side
99- #### API Contract Implementation
104+ ## Sample Server
105+ ### API Implementation
100106``` csharp
101107[Route (" api/[controller]" )]
102108public class GuidelineController : Controller , IGuidelineApi
103109{
104- private readonly ILoggerFactory _loggerFactory ;
105-
106- protected ILogger Logger { get ; }
107-
108- public GuidelineController (ILoggerFactory loggerFactory )
109- {
110- _loggerFactory = loggerFactory ;
111- Logger = _loggerFactory .CreateLogger <GuidelineController >();
112- }
113-
114- [HttpGet (nameof (GetPostsAsync ))]
115- public async Task <IEnumerable <Post >> GetPostsAsync ()
110+ [HttpGet (nameof (GetEnumerableModels ))]
111+ public Task <IEnumerable <SampleModel >> GetEnumerableModels ()
116112 {
117- var httpRequest = new HttpRequestMessage (HttpMethod .Get , new Uri (" https://jsonplaceholder.typicode.com/posts" ));
118- var response = await Factory .Client .SendAsync (httpRequest );
119- var content = await response .Content .ReadAsStringAsync ();
120- var items = JsonConvert .DeserializeObject <List <Post >>(content );
121- Logger .LogDebug ($" {nameof (GetPostsAsync )}, PostsCount:{items .Count }" );
113+ .. .
122114 return items ;
123115 }
124116
125- [HttpGet (nameof (GetWithReferenceType ))]
126- public async Task GetWithReferenceType ([FromQuery ]SimpleModel model )
127- {
128- var serializedModel = JsonConvert .SerializeObject (model );
129- Logger .LogDebug ($" {nameof (GetWithReferenceType )}, Model: {serializedModel }" );
130- await Task .Delay (900 );
131- }
132-
133- [HttpGet (nameof (PrimitiveReturn ))]
134- public int PrimitiveReturn (int i , string s , long l , DateTime dt )
135- {
136- Logger .LogDebug ($" {nameof (PrimitiveReturn )}, i:{i }, s:{s }, l:{l }, dt:{dt }" );
137- return i + 10 ;
138- }
139-
140- [HttpPost (nameof (TaskActionPost ))]
141- public async Task TaskActionPost ([FromBody ]SimpleModel model )
142- {
143- var serializedModel = JsonConvert .SerializeObject (model );
144- Logger .LogDebug ($" {nameof (TaskActionPost )}, Model: {serializedModel }" );
145- await Task .Delay (900 );
146- }
147-
148- [HttpGet (nameof (TaskOperation ))]
149- public async Task TaskOperation ()
117+ [HttpPost (nameof (TaskComplexTypeModel ))]
118+ public async Task TaskComplexTypeModel ([FromBody ]ComplexTypeModel model )
150119 {
151- await Task .Delay (2000 );
152- Logger .LogDebug ($" {nameof (TaskOperation )}, long running process completed!" );
120+ .. .
153121 }
154122
155- [HttpGet (nameof (VoidOperation ))]
156- public void VoidOperation ( )
123+ [HttpPost (nameof (TaskActionBarMultipartFormData ))]
124+ public Task TaskActionBarMultipartFormData ( Bar model )
157125 {
158- var str = " Hello World!" ;
159- Logger .LogDebug ($" {nameof (VoidOperation )}, {str }" );
126+ .. .
160127 }
161128}
162129```
163130
164- #### Multipart form data:
165- Proxy sends all POST methods as JSON but if the method parameter model contains IFormFile type property it converts the content-type to multipart/form-data. In this case, use any model to POST multipart/form-data to API without [ FromBody] attribute on action parameter. For example:
166-
167- ``` csharp
168- // Interface
169- [HttpPostMarker ]
170- Task < AlbumViewModel > SaveAlbumSubmitAsync (AlbumViewModelSubmit model )
171- ```
172-
173- ``` csharp
174- // API Controller
175- [HttpPost (nameof (SaveAlbumSubmitAsync ))]
176- public async Task < AlbumViewModel > SaveAlbumSubmitAsync (AlbumViewModelSubmit model )
177- ```
178-
179- #### Unit Testing
131+ ### Unit Testing
180132Use [ HttpLive] ( https://github.com/gencebay/httplive )
181133
182134 httplive -p 5003,5004 -d test/NetCoreStack.Proxy.Tests/httplive.db
0 commit comments