restful-dummy-server 1.0.2 → 1.0.4

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 +180 -1
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -2,4 +2,183 @@
2
2
  This can be used to mock Rest API responses.
3
3
 
4
4
  ## How to install
5
- npm install -g restful-dummy-server
5
+ npm install -g restful-dummy-server
6
+
7
+ ## How to use
8
+ ### CLI options
9
+
10
+ #### 1. port
11
+ ```js
12
+ "scripts": {
13
+ "start": "restful-dummy-server -port 4000"
14
+ }
15
+ ```
16
+
17
+ This will start restful dummy server on port 4000
18
+
19
+
20
+ #### 2. host
21
+ You can also mention host.
22
+ ```js
23
+ "scripts": {
24
+ "start": "restful-dummy-server -port 4000 -host xx.xx.xx.xx"
25
+ }
26
+ ```
27
+
28
+ #### 3. static
29
+ ```js
30
+ "scripts": {
31
+ "start": "restful-dummy-server -port 4000 -static ./data"
32
+ }
33
+ ```
34
+
35
+ **static** is used to know the relative path of a folder where all statics files are hosted. Which then would be used by Dummy server to download files against the rest api dowbloaded request.
36
+ Here this folder is **data**.
37
+
38
+
39
+ #### 4. config
40
+ ```js
41
+ "scripts": {
42
+ "start": "restful-dummy-server -port 4000 -static ./data -config ./test"
43
+ }
44
+ ```
45
+
46
+ **config** is used to know the relative path of a folder which are having dummy request response instruction files in **.json** extensions only.
47
+
48
+ Note -
49
+ 1. Assuming **port** is 4000 for all below examples.
50
+ 2. **data** folder is having **test.png** file
51
+
52
+ Example 1-
53
+ **test/config.json**
54
+
55
+ ```js
56
+ [{
57
+ "request": {
58
+ "url": "/get/message",
59
+ "method": "get"
60
+ },
61
+ "response": {
62
+ "headers": {},
63
+ "body": "Hello Dummy Server"
64
+ }
65
+ }]
66
+ ```
67
+
68
+ In this case if you hit http://localhost:5000/get/message then you will get **Hello Dummy Server** as response.
69
+
70
+
71
+ Example 2-
72
+ **test/config.json**
73
+
74
+ ```js
75
+ [{
76
+ "request": {
77
+ "url": "/get/:message",
78
+ "method": "get"
79
+ },
80
+ "response": {
81
+ "headers": {},
82
+ "body": { "message": "Hello Dummy Server" }
83
+ }
84
+ }]
85
+ ```
86
+
87
+ In this case if you hit http://localhost:5000/get/test or http://localhost:5000/get/msg etc. then you will get **{ "message": "Hello Dummy Server" }** as response.
88
+
89
+
90
+ Example 3-
91
+ **test/config.json**
92
+
93
+ ```js
94
+ [{
95
+ "request": {
96
+ "url": "/get/png/*.*",
97
+ "method": "get"
98
+ },
99
+ "response": {
100
+ "headers": {
101
+ "Content-Disposition": "attachment;filename= test.png;"
102
+ },
103
+ "body": "./test.png"
104
+ }
105
+ }]
106
+ ```
107
+
108
+ In this case if you hit http://localhost:5000/get/png/abc.png or http://localhost:5000/get/png/msg.png etc. then **test.png** will be downloaded as response.
109
+
110
+
111
+ Example 4-
112
+ **test/config.json**
113
+
114
+ ```js
115
+ [{
116
+ "request": {
117
+ "url": "/get/**/*.*",
118
+ "method": "get"
119
+ },
120
+ "response": {
121
+ "headers": {
122
+ "Content-Disposition": "attachment;filename= test.png;"
123
+ },
124
+ "body": "./test.png"
125
+ }
126
+ }]
127
+ ```
128
+
129
+ In this case if you hit http://localhost:5000/get/png/abc.png or http://localhost:5000/get/png/png2/msg.jpeg etc. then **test.png** will be downloaded as response.
130
+
131
+
132
+ Example 5-
133
+ **test/config.json**
134
+
135
+ ```js
136
+ [{
137
+ "request": {
138
+ "url": "/get/**/*.png",
139
+ "method": "get"
140
+ },
141
+ "response": {
142
+ "headers": {
143
+ "Content-Disposition": "attachment;filename= test.png;"
144
+ },
145
+ "body": "./test.png"
146
+ }
147
+ }]
148
+ ```
149
+
150
+ In this case if you hit http://localhost:5000/get/png/abc.png or http://localhost:5000/get/png/png2/msg.png etc. then **test.png** will be downloaded as response.
151
+
152
+
153
+ Example 6-
154
+ **test/config.json**
155
+
156
+ ```js
157
+ [{
158
+ "request": {
159
+ "url": "/get/**/*.png",
160
+ "method": "get"
161
+ },
162
+ "response": {
163
+ "headers": {
164
+ "Content-Disposition": "attachment;filename= test.png;"
165
+ },
166
+ "body": "./test.png",
167
+ "delay": 2000
168
+ }
169
+ }]
170
+ ```
171
+
172
+ Above **delay** is the special attribute which would cause Dummy server to respond in 2000 milliseconds.
173
+
174
+
175
+ #### 5. proxy
176
+ ```js
177
+ "scripts": {
178
+ "start": "restful-dummy-server -port 4000 -static ./data -config ./test -proxy localhost:2000"
179
+ }
180
+ ```
181
+
182
+ If **proxy** is provided then Dummy server will redirect the request to the proxy server if there is no matching record found.
183
+
184
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "restful-dummy-server",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "This can be used to mock restful api responses.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {