You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Below is a minimal example of intercepting a request to an HTTP API for a JSON resource to return a custom response:
34
+
##### Fluent API
35
+
36
+
Below is a minimal example of intercepting a request to an HTTP API for a JSON resource to return a custom response using the fluent API:
35
37
36
38
```csharp
37
39
// using JustEat.HttpClientInterception;
@@ -54,6 +56,62 @@ var json = await client.GetStringAsync("http://public.je-apis.com/terms");
54
56
55
57
`HttpRequestInterceptionBuilder` objects are mutable, so properties can be freely changed once a particular setup has been registered with an instance of `HttpClientInterceptorOptions` as the state is captured at the point of registration. This allows multiple responses and paths to be configured from a single `HttpRequestInterceptionBuilder` instance where multiple registrations against a common hostname.
56
58
59
+
##### _HTTP Bundle_ Files
60
+
61
+
HTTP requests to intercept can also be configured in an _"HTTP bundle"_ file, which can be used to store the HTTP requests to intercept and their corresponding responses as JSON.
62
+
63
+
This functionality is analogous to our [_Shock_](https://github.com/justeat/Shock"Shock") pod for iOS.
64
+
65
+
###### JSON
66
+
67
+
Below is an example bundle file, which can return content in formats such as a string, JSON and base64-encoded data.
68
+
69
+
The full JSON schema for HTTP bundle files can be found [here](https://raw.githubusercontent.com/justeat/httpclient-interception/master/src/HttpClientInterception/Bundles/http-request-bundle-schema.json"JSON Schema for HTTP request interception bundles for use with JustEat.HttpClientInterception.").
Further examples of using HTTP bundles can be found in the [tests](https://github.com/justeat/httpclient-interception/blob/master/tests/HttpClientInterception.Tests/Bundles/BundleExtensionsTests.cs"BundleExtensionsTests.cs"), such as for changing the response code, the HTTP method, and matching to HTTP requests based on the request headers.
114
+
57
115
#### Fault Injection
58
116
59
117
Below is a minimal example of intercepting a request to inject an HTTP fault:
@@ -177,23 +235,24 @@ Further examples of using the library can be found by following the links below:
177
235
178
236
### Benchmarks
179
237
180
-
Generated with the [Benchmarks project](https://github.com/justeat/httpclient-interception/blob/master/tests/HttpClientInterception.Benchmarks/InterceptionBenchmarks.cs"JustEat.HttpClientInterception benchmark code") using [BenchmarkDotNet](https://github.com/dotnet/BenchmarkDotNet"BenchmarkDotNet on GitHub.com") using commit [e189875](https://github.com/justeat/httpclient-interception/commit/e18987518f279ece7ad4631d21c5e986733fdab3"Benchmark commit") on 14/10/2018.
238
+
Generated with the [Benchmarks project](https://github.com/justeat/httpclient-interception/blob/master/tests/HttpClientInterception.Benchmarks/InterceptionBenchmarks.cs"JustEat.HttpClientInterception benchmark code") using [BenchmarkDotNet](https://github.com/dotnet/BenchmarkDotNet"BenchmarkDotNet on GitHub.com") using commit [b60b750](https://github.com/justeat/httpclient-interception/commit/b60b750c7b63934b91a3b3e81df4b5506e3668a5"Benchmark commit") on 24/03/2019.
0 commit comments