restful-dummy-server 1.0.2 → 1.0.3

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