Skip to content

Commit 705f501

Browse files
committed
Updated docs
1 parent 21a0d0e commit 705f501

File tree

1 file changed

+184
-6
lines changed

1 file changed

+184
-6
lines changed

netmockery/documentation.md

Lines changed: 184 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ Command line:
1212

1313
netmockery.exe p:\ath\to\endpoint\directory
1414

15-
Netmockery starts and listens on port ``5000``.
15+
Netmockery starts and listens on ``localhost`` port ``5000``.
16+
17+
To bind to another address/port, use the ``--url`` command line parameter. The command below binds netmockery to all network interfaces using port 9876.
18+
19+
netmockery.exe p:\ath\to\endpoint\directory --url http://*:9876
1620

1721
## Installing as windows service
1822

@@ -80,14 +84,15 @@ Example ``endpoint.json``:
8084
The first step in handling incoming request is to check the incoming request's request path. The request path is matched against each ``pathregex`` for all
8185
endpoints in the endpoint collection directory.
8286

83-
Exactly one endpoint must match the request. If zero or more than one endpoint matches the incoming request,
84-
netmockery writes an error message to the console output, and returns nothing to the client.
87+
Exactly one endpoint must match the request. If zero endpoints matches the incoming request,
88+
netmockery writes an error message to the console output, and returns nothing to the client. If more than one endpoint
89+
matches the incoming request, netmockery writes an error message to the console output, and returns nothing to the client.
8590

8691
The second and final step in the request matching process is to check the incoming request against the list of rules in ``responses``. The first rule that matches
8792
the request will be used for creating the response. If no rule matches the request, netmockery writes an error message to the console output and returns nothing to
8893
the client.
8994

90-
The ``match`` paramter within the ``responses`` list can match requests using one of these methods:
95+
The ``match`` parameter within the ``responses`` list can match requests using one of these methods:
9196

9297
### Match any request
9398

@@ -140,12 +145,184 @@ Inside a script, the following global variables and functions are available:
140145

141146
TODO: More scripting documentation.
142147

148+
### Forwarding requests
149+
150+
You can configure a rule to forward the request to an external service:
151+
152+
* ``"strippath": "^/myservice"``: A reqular expression that is removed from the request path when calling the external url.
153+
* ``"forward": "https://example.com/the/real/service"``: Forwards the request to the specified url
154+
* ``"proxy": "http://proxy:port"``: (optional) Uses the specified proxy when doing the request
155+
156+
#### Example
157+
158+
``endpoint.json``:
159+
160+
{
161+
"name": "MyEndpoint",
162+
"pathregex": "^/myservice",
163+
"responses": [
164+
{
165+
"match": { "regex": "foobar" },
166+
"file": "response.xml",
167+
"contenttype": "text/xml"
168+
},
169+
170+
{
171+
"match": { },
172+
"strippath": "^/myservice"
173+
"forward": "https://example.com/the/real/service",
174+
}
175+
]
176+
}
177+
178+
Request ``http://netmockery:NNNN/myservice/resource/foobar``:
179+
180+
* The first rule matches
181+
* ``response.xml`` is returned to the client
182+
183+
Request ``http://netmockery:NNNN/myservice/resource/another``:
184+
185+
* The last rule (``"match": {}`` == any request) matches
186+
* The request path is ``/myservice/resource/another``
187+
* Stripping ``^/myservice`` from the request path, we get ``/resource/another``
188+
* ``/resource/another`` is appended to the ``forward`` URL ``https://example.com/the/real/service``
189+
* Netmockery makes a HTTP request to ``https://example.com/the/real/service/resource/another`` and returns the response to the client
190+
191+
143192
### Common parameters
144193

145-
* ``contenttype``: Sets the content-type header. Not used for the forward request response creator.
194+
* ``contenttype``: Sets the mediatype part of the content-type header. Not used for the forward request response creator.
195+
* ``charset``: Sets the charset part of the content-type header. Not used for the forward request response creator. See the section "Encodings" below
196+
for more information.
146197
* ``replacements``: TODO: Document. Not used for the forward request response creator.
147198
* ``delay``: If set, netmockery waits for the specified number of seconds before returning the response to the client.
148199

200+
201+
### Encodings
202+
203+
#### Netmockery input file encoding
204+
205+
* All netmockery *input* files should be in UTF-8 encoding:
206+
* Json configuration files
207+
* Static file responses (via ``"file"``)
208+
* C# script files
209+
* Test expectation response files
210+
211+
#### HTTP Response encoding and the Content-Type header
212+
213+
* The ``charset`` parameter determines the response encoding for netmockery responses (expect for forwarded external requests).
214+
* If no charset parameter is specified, netmockery uses ISO-8859-1 (latin1) encoding.
215+
* The Content-Type header for the responses is set in this manner:
216+
* If ``contenttype`` is NOT set, no ``Content-Type`` header is set for the responses
217+
* If ``contenttype`` is set to ``foo/bar`` and ``charset`` is NOT set
218+
1. netmockery encodes the response using the ISO-8859-1 encoding
219+
2. ``Content-Type`` = ``foo/bar; charset=iso-8859-1``
220+
* If ``contenttype`` is set to ``foo/bar`` and ``charset`` is set to one of the supported encodings (see list below)
221+
1. netmockery encodes the response using the specified encoding (eg. ``utf-8``)
222+
2. ``Content-Type`` = ``foo/bar; charset=utf-8``
223+
* For forwarded external requests, not encoding and content-type handling is done.
224+
225+
#### Valid charset names (not case sensitive)
226+
227+
US-ASCII
228+
ISO_8859-1:1987
229+
ISO_8859-2:1987
230+
ISO_8859-3:1988
231+
ISO_8859-4:1988
232+
ISO_8859-5:1988
233+
ISO_8859-6:1987
234+
ISO_8859-7:1987
235+
ISO_8859-8:1988
236+
ISO_8859-9:1989
237+
Shift_JIS
238+
Extended_UNIX_Code_Packed_Format_for_Japanese
239+
DIN_66003
240+
NS_4551-1
241+
SEN_850200_B
242+
KS_C_5601-1987
243+
ISO-2022-KR
244+
EUC-KR
245+
ISO-2022-JP
246+
GB_2312-80
247+
UNICODE-1-1-UTF-7
248+
UTF-8
249+
ISO-8859-13
250+
ISO-8859-15
251+
GBK
252+
GB18030
253+
ISO-10646-UCS-2
254+
UTF-7
255+
UTF-16BE
256+
UTF-16LE
257+
UTF-16
258+
UTF-32
259+
UTF-32BE
260+
UTF-32LE
261+
IBM850
262+
IBM862
263+
IBM-Thai
264+
GB2312
265+
Big5
266+
macintosh
267+
IBM037
268+
IBM273
269+
IBM277
270+
IBM278
271+
IBM280
272+
IBM284
273+
IBM285
274+
IBM290
275+
IBM297
276+
IBM420
277+
IBM423
278+
IBM424
279+
IBM437
280+
IBM500
281+
IBM852
282+
IBM855
283+
IBM857
284+
IBM860
285+
IBM861
286+
IBM863
287+
IBM864
288+
IBM865
289+
IBM869
290+
IBM870
291+
IBM871
292+
IBM880
293+
IBM905
294+
IBM1026
295+
KOI8-R
296+
HZ-GB-2312
297+
IBM866
298+
IBM775
299+
KOI8-U
300+
IBM00858
301+
IBM00924
302+
IBM01140
303+
IBM01141
304+
IBM01142
305+
IBM01143
306+
IBM01144
307+
IBM01145
308+
IBM01146
309+
IBM01147
310+
IBM01148
311+
IBM01149
312+
Big5-HKSCS
313+
windows-874
314+
windows-1250
315+
windows-1251
316+
windows-1252
317+
windows-1253
318+
windows-1254
319+
windows-1255
320+
windows-1256
321+
windows-1257
322+
windows-1258
323+
TIS-620
324+
325+
149326
<a name="tests"></a>
150327
# Writing tests
151328

@@ -214,4 +391,5 @@ TODO: delay parameter
214391

215392
TODO: index.md documentation
216393

217-
TODO: other commands, dump
394+
TODO: other commands, dump
395+

0 commit comments

Comments
 (0)