Skip to content

Commit 4d2adc6

Browse files
committed
README updated, httplive sync
1 parent 23a81ae commit 4d2adc6

File tree

5 files changed

+31
-79
lines changed

5 files changed

+31
-79
lines changed

README.md

Lines changed: 27 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -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
6672
public 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]")]
102108
public 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
180132
Use [HttpLive](https://github.com/gencebay/httplive)
181133

182134
httplive -p 5003,5004 -d test/NetCoreStack.Proxy.Tests/httplive.db

test/NetCoreStack.Proxy.Mvc.Hosting/Controllers/GuidelineController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ public Task<CollectionResult<SampleModel>> GetCollectionStreamTask()
7070
return null;
7171
}
7272

73-
[HttpPost(nameof(TaskActionPost))]
74-
public async Task TaskActionPost([FromBody]ComplexTypeModel model)
73+
[HttpPost(nameof(TaskComplexTypeModel))]
74+
public async Task TaskComplexTypeModel([FromBody]ComplexTypeModel model)
7575
{
7676
await Task.CompletedTask;
7777
_logger.LogWarning(JsonConvert.SerializeObject(model));

test/NetCoreStack.Proxy.Test.Contracts/IGuidelineApi.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public interface IGuidelineApi : IApiContract
2727
/// <param name="model"></param>
2828
/// <returns></returns>
2929
[HttpPostMarker]
30-
Task TaskActionPost(ComplexTypeModel model);
30+
Task TaskComplexTypeModel(ComplexTypeModel model);
3131

3232
[HttpPostMarker(ContentType = ContentType.MultipartFormData)]
3333
Task TaskActionBarMultipartFormData(Bar model);

test/NetCoreStack.Proxy.Tests/ProxyCreationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public async Task GetWithComplexReferenceTypeTest()
9898
public async Task TaskCallHttpPostWithReferenceTypeParameterTest()
9999
{
100100
var guidelineApi = Resolver.GetService<IGuidelineApi>();
101-
await guidelineApi.TaskActionPost(TypesModelHelper.GetComplexTypeModel());
101+
await guidelineApi.TaskComplexTypeModel(TypesModelHelper.GetComplexTypeModel());
102102
}
103103

104104
[Fact]
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)