apimock-rs 4.7.1 β†’ 4.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +12 -161
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -51,10 +51,6 @@ apimock-rs does not preload responses. Each response file is read only when a re
51
51
  as validated with k6 load testing.
52
52
  You can run UI development and automated tests continuously without worrying about server instability.
53
53
 
54
- ### πŸ“– Documentation
55
-
56
- For more details, **🧭 check out [the docs](https://apimokka.github.io/apimock-rs/)**.
57
-
58
54
  ---
59
55
 
60
56
  ## Quick start
@@ -83,6 +79,15 @@ You may also check it out with browser to visit http://localhost:3001/api/v1/hel
83
79
 
84
80
  You now have a running REST endpoint.
85
81
 
82
+ ### `npx apimock` variation
83
+
84
+ | command | result |
85
+ | --- | --- |
86
+ | `npx apimock` | Run with all default parameters. |
87
+ | `npx apimock -p 4000` | Run with custom port. |
88
+ | `npx apimock -d tests/apimock-dyn-route` | Run with custom root dir on server response. |
89
+ | `npx apimock -c apimock.toml` | Run with config file giving rich features. Running `npx apimock --init` beforehand is required. |
90
+
86
91
  ### Vite project integration
87
92
 
88
93
  An example of **scripts** section in **package.json** is as below.
@@ -108,167 +113,13 @@ Run:
108
113
  npm run dev
109
114
  ```
110
115
 
111
- ### `npx apimock` variation
112
-
113
- | command | result |
114
- | --- | --- |
115
- | `npx apimock` | Run with all default parameters. |
116
- | `npx apimock -p 4000` | Run with custom port. |
117
- | `npx apimock -d tests/apimock-dyn-route` | Run with custom root dir on server response. |
118
- | `npx apimock -c apimock.toml` | Run with config file giving rich features. Running `npx apimock --init` beforehand is required. |
119
-
120
116
  ---
121
117
 
122
- ## Configuration reference
123
-
124
- Everything below describes the TOML config files. Run `npx apimock --init` (or
125
- `apimock --init`) once to scaffold `apimock.toml` and `apimock-rule-set.toml`
126
- into the current directory, then tweak to taste.
118
+ ### πŸ“– Documentation - guides and references
127
119
 
128
- ### `apimock.toml` β€” top-level file
120
+ For more details, **🧭 check out our [full documentation](https://apimokka.github.io/apimock-rs/)**.
129
121
 
130
- ```toml
131
- [listener]
132
- ip_address = "127.0.0.1" # interface to bind
133
- port = 3001 # plaintext HTTP port
134
-
135
- [listener.tls] # optional β€” enables HTTPS
136
- cert = "./cert.pem"
137
- key = "./key.pem"
138
- # port = 3002 # optional β€” if omitted, HTTPS replaces HTTP on the port above
139
-
140
- [log]
141
- verbose = { header = true, body = true }
142
-
143
- [service]
144
- strategy = "first_match" # only value supported today
145
- rule_sets = ["apimock-rule-set.toml"] # paths, resolved relative to this file
146
- middlewares = [] # Rhai scripts, resolved relative to this file
147
- fallback_respond_dir = "." # folder served when no rule matches
148
- ```
149
-
150
- | Section / field | Required | Default | Notes |
151
- | --- | --- | --- | --- |
152
- | `listener.ip_address` | no | `127.0.0.1` | Bind address. `0.0.0.0` to accept from other machines. |
153
- | `listener.port` | no | `3001` | Plaintext HTTP port. |
154
- | `listener.tls.cert` / `.key` | yes if `[listener.tls]` set | β€” | PEM files. Any key format `rustls-pki-types` accepts (PKCS#8, PKCS#1, SEC1). |
155
- | `listener.tls.port` | no | same as `listener.port` | When omitted, the single port serves HTTPS only β€” no plaintext listener is started. |
156
- | `log.verbose.header` | no | `false` | Log each request's headers. |
157
- | `log.verbose.body` | no | `false` | Log each request's URL query and JSON body (pretty-printed). |
158
- | `service.strategy` | no | `first_match` | Currently the only strategy β€” the first rule that matches wins. |
159
- | `service.rule_sets` | no | `[]` | See **Rule-set schema** below. Paths relative to this file. |
160
- | `service.middlewares` | no | `[]` | Rhai script paths, relative to this file. |
161
- | `service.fallback_respond_dir` | no | `.` | Folder served when nothing in `rule_sets` or `middlewares` handled the request. |
162
-
163
- ### Rule-set schema β€” `apimock-rule-set.toml`
164
-
165
- ```toml
166
- [prefix] # optional
167
- url_path = "/api/v1/" # prepended to every rule's url_path
168
- respond_dir = "apimock-rule-sets/@respond-dir" # prepended to every rule's file_path
169
-
170
- [default] # optional
171
- delay_response_milliseconds = 0 # applied to every rule in this set unless overridden
172
-
173
- [[rules]]
174
- when.request.url_path = "complicated"
175
- when.request.method = "POST"
176
- when.request.headers.authorization = { value = "Bearer eyJhb", op = "starts_with" }
177
- when.request.headers.user = { value = "user1" } # op defaults to "equal"
178
- when.request.body.json."user.id" = { value = "42" }
179
- respond = { text = "Strictly authorized !" }
180
-
181
- [[rules]]
182
- when.request.url_path = { value = "/public/", op = "starts_with" }
183
- respond = { file_path = "public/index.json", csv_records_key = "records" }
184
-
185
- [[rules]]
186
- when.request.url_path = ""
187
- respond = { status = 403 }
188
- ```
189
-
190
- #### `when.request` β€” match conditions (AND-ed together)
191
-
192
- | Field | Accepts | Purpose |
193
- | --- | --- | --- |
194
- | `url_path` | string *or* `{ value, op }` | URL path match. String form is shorthand for `op = "equal"`. |
195
- | `method` | `"GET"` / `"POST"` / `"PUT"` / `"DELETE"` | HTTP method. Omit to match any method. |
196
- | `headers` | `{ header-name = { value, op } }` map | Every listed header must match. Header names are matched case-insensitively per HTTP. |
197
- | `body.json` | `{ json-path = { value, op } }` map | JSON body match β€” see **JSONPath form** below. |
198
-
199
- #### `respond` β€” response shape
200
-
201
- Exactly one of `file_path` / `text` / `status` must be present. (`text` may be combined with `status` to set the response code.)
202
-
203
- | Field | Type | Purpose |
204
- | --- | --- | --- |
205
- | `file_path` | string | File under `prefix.respond_dir` (or the working dir if no prefix). Extension decides content type; `.json` / `.json5` / `.csv` served as JSON, other text types served verbatim with an inferred `Content-Type`, binary types (images, audio, video, `.pdf`, `.zip`) served with the corresponding binary `Content-Type`. |
206
- | `text` | string | Return this string verbatim. Content type `text/plain; charset=utf-8`. |
207
- | `status` | integer (100–999) | HTTP status code. With `text`, sets the status; alone, returns an empty body with that status. Cannot be combined with `file_path`. |
208
- | `headers` | `{ name = value }` map | Extra response headers. |
209
- | `delay_response_milliseconds` | integer | Sleep this long before responding β€” useful for simulating slow backends in UI tests. |
210
- | `csv_records_key` | string | Only meaningful when `file_path` points at a `.csv`. The JSON response wraps the rows as `{ "<key>": [...] }` using this value; defaults to `"records"`. |
211
-
212
- #### `op` β€” comparison operators
213
-
214
- Every `{ value, op }` structure accepts these `op` values. If `op` is omitted it defaults to `equal`.
215
-
216
- | `op` | Meaning | Example |
217
- | --- | --- | --- |
218
- | `equal` (default) | Exact string match | `{ value = "user1" }` matches `user1` only |
219
- | `not_equal` | Anything *but* an exact match | `{ value = "guest", op = "not_equal" }` matches everything except `guest` |
220
- | `starts_with` | String starts with value | `{ value = "Bearer ", op = "starts_with" }` matches any Bearer token |
221
- | `contains` | Value appears anywhere inside the target | `{ value = "admin", op = "contains" }` matches `superadmin`, `admin-1`, etc. |
222
- | `wild_card` | Glob match β€” see below | `{ value = "/api/v*/users/?", op = "wild_card" }` |
223
-
224
- ##### Wildcard / glob syntax (`wild_card`)
225
-
226
- The glob matcher supports exactly two metacharacters, matching the common case without the complexity of a full regex engine:
227
-
228
- | Token | Matches |
229
- | --- | --- |
230
- | `?` | Exactly one character |
231
- | `*` | Zero or more characters |
232
-
233
- Examples:
234
-
235
- | Pattern | Matches | Doesn't match |
236
- | --- | --- | --- |
237
- | `hello` | `hello` | `hell`, `hello!` |
238
- | `file*.txt` | `file.txt`, `file123.txt`, `files/doc.txt` | `file.csv` |
239
- | `file?.txt` | `file1.txt`, `fileX.txt` | `file.txt`, `file12.txt` |
240
- | `a*b?c` | `axyzbxc`, `ab1c` | `abc` |
241
- | `*test*` | `my_test_file`, `test` | `tes` |
242
- | `こんにけ?δΈ–η•Œ` | `γ“γ‚“γ«γ‘γ―δΈ–η•Œ` | Unicode is respected per code point. |
243
-
244
- This is NOT a regex. Sequences such as `.`, `[…]`, `(…)`, `+`, `^`, `$` are matched literally.
245
-
246
- ##### JSONPath form (`body.json` and `csv_records_key`)
247
-
248
- The JSONPath support is deliberately minimal β€” only the "object key" and "array index" forms, joined by `.`. This covers every real-world body-match need without exposing a full jsonpath engine that users would then have to learn.
249
-
250
- | Input | Meaning |
251
- | --- | --- |
252
- | `user` | Top-level key `user` |
253
- | `user.id` | `user` β†’ `id` (nested object) |
254
- | `items.0` | First element of array `items` |
255
- | `orders.2.total` | Array index 2 of `orders`, then key `total` |
256
- | `a.b.c` | Three-level nested object lookup |
257
-
258
- If any segment is missing or has the wrong shape (e.g. a numeric segment against an object), the rule simply does not match β€” no error, because "missing" is a useful matchable condition.
259
-
260
- #### `prefix`
261
-
262
- | Field | Effect |
263
- | --- | --- |
264
- | `url_path` | Prepended to every rule's `when.request.url_path` before matching. Leading/trailing slashes are normalised. The `contains` operator deliberately ignores the prefix β€” it matches against the raw `url_path` value β€” because "contains" usually means "substring anywhere in the full request path", and re-applying a prefix there would be surprising. |
265
- | `respond_dir` | Prepended to every rule's `respond.file_path`. Resolved relative to the rule-set file's directory, not the working dir β€” so configs travel cleanly between machines. |
266
-
267
- #### `default`
268
-
269
- | Field | Effect |
270
- | --- | --- |
271
- | `delay_response_milliseconds` | Default delay for rules in this set that don't specify their own. |
122
+ - Configuration Reference: πŸ“‹ [View all settings here](https://apimokka.github.io/apimock-rs/user-guide/configuration-reference.html)
272
123
 
273
124
  ---
274
125
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apimock-rs",
3
- "version": "4.7.1",
3
+ "version": "4.7.2",
4
4
  "description": "HTTP(S) mock server. Drop JSON files into a folder and your API immediately exists.",
5
5
  "author": "nabbisen<nabbisen@scqr.net>",
6
6
  "license": "Apache-2.0",