Skip to content

Commit c46616c

Browse files
authored
Update README.md
1 parent 39561d6 commit c46616c

File tree

1 file changed

+51
-4
lines changed

1 file changed

+51
-4
lines changed

README.md

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ FakeApi is for you!
1919
# v1.2.0 Release note
2020

2121
- Improvement of configuration files reading
22-
- Adding the capability to split the api configurations files into several files
22+
- Adding the capability to split the api configurations files into multilpe files. Please read 'Organize your configurations files' section
23+
- Adding a default implementation of IHttpRequester
2324

2425
# How to use FakeApi?
2526

@@ -81,6 +82,28 @@ For each web api you can set several actives responses. One per pair url/method.
8182
Note that you can use template segment in your url configuration (/{idUser}).
8283
You can also override all default values defined at the root path in each apis configuration.
8384

85+
- #### Organize your configurations files
86+
87+
You can configure FakeApi in a single file. But you can now split your Apis configurations files into multiple files. To do that, just provide all directories where FakeApi can find api configurations files by this way :
88+
89+
```json
90+
{
91+
"defaultDelay": 250,
92+
"defaultHttpCode": 200,
93+
"defaultMethod": "GET",
94+
"apisDirectories": [
95+
"Config/Api/User"
96+
]
97+
}
98+
```
99+
100+
In summary, I advise you as in the example below :
101+
- declare a main file (api.cfg.json) with all default values that you need and all api configurations files directories
102+
- create one configuration file per api type (usersApi.cfg.json, ordersApi.cfg.json etc...)
103+
- and create one json response file per request (getUserById.json, postUser1.json etc...)
104+
105+
![Config example](https://github.com/redisdev/FakeApi/blob/release_v1.2.0/config.png?raw=true)
106+
84107
- #### How to return data from file?
85108

86109
Simply set the "file" property into your api configuration:
@@ -216,8 +239,7 @@ using (var stream = new StreamReader(getUserResponse.GetResponseStream()))
216239
````
217240
- #### IHttpRequester
218241

219-
In production, replace the FakeHttpRequester implemention of FakeApi by your own implementation.
220-
FakeHttpRequester implements IHttpRequester to provide method to send HttpWebRequest synchronous or asynchronous.
242+
In production, replace the FakeHttpRequester implementation by DefaultHttpRequester provided by FakeApi. Or you can also write your own implementation of IHttpRequester interface.
221243

222244
```csharp
223245

@@ -237,6 +259,31 @@ public interface IHttpRequester
237259
Task<HttpWebResponse> GetResponseAsync(HttpWebRequest request);
238260
}
239261

262+
public class DefaultHttpRequester: IHttpRequester
263+
{
264+
public HttpWebResponse GetResponse(WebRequest request)
265+
{
266+
if(request == null)
267+
{
268+
throw new ArgumentNullException(nameof(request));
269+
}
270+
271+
var response = request.GetResponse();
272+
return response as HttpWebResponse;
273+
}
274+
275+
public async Task<HttpWebResponse> GetResponseAsync(WebRequest request)
276+
{
277+
if (request == null)
278+
{
279+
throw new ArgumentNullException(nameof(request));
280+
}
281+
282+
var response = await request.GetResponseAsync();
283+
return response as HttpWebResponse;
284+
}
285+
}
286+
240287
```
241288

242289
#### List of available default HttpWebResponse properties
@@ -289,7 +336,7 @@ public interface IHttpRequester
289336
- string name
290337
- string value
291338

292-
#### Json configuration full example
339+
#### Single file Json configuration full example
293340

294341
```json
295342

0 commit comments

Comments
 (0)