gg-express 1.0.25 → 1.0.26
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.
- package/dist/GGApi.js +1 -3
- package/dist/test.js +17 -2
- package/package.json +1 -1
- package/readme.md +91 -0
- package/src/GGApi.ts +1 -3
- package/src/test.ts +18 -2
package/dist/GGApi.js
CHANGED
|
@@ -70,9 +70,7 @@ function run() {
|
|
|
70
70
|
return __awaiter(this, void 0, void 0, function* () {
|
|
71
71
|
const api = new GGApi();
|
|
72
72
|
const data = yield api.post("/api/item", {
|
|
73
|
-
parameter: {
|
|
74
|
-
bankID: 1,
|
|
75
|
-
},
|
|
73
|
+
parameter: { bankID: 2 },
|
|
76
74
|
data: [{ id: 2, name: "2" }],
|
|
77
75
|
});
|
|
78
76
|
const data2 = yield api.get("/api/users", {});
|
package/dist/test.js
CHANGED
|
@@ -37,12 +37,13 @@ function run() {
|
|
|
37
37
|
ggapp.post("/api/item", {
|
|
38
38
|
requireParams: {
|
|
39
39
|
parameter: {
|
|
40
|
-
|
|
40
|
+
lotNumber: "number",
|
|
41
41
|
},
|
|
42
42
|
dataType: "arrayObject",
|
|
43
43
|
structure: {
|
|
44
44
|
id: "number",
|
|
45
45
|
name: "string",
|
|
46
|
+
price: "number",
|
|
46
47
|
},
|
|
47
48
|
},
|
|
48
49
|
responseStructure: {
|
|
@@ -54,7 +55,21 @@ function run() {
|
|
|
54
55
|
},
|
|
55
56
|
},
|
|
56
57
|
}, (req, res, next) => {
|
|
57
|
-
|
|
58
|
+
// in body or query, you can access only requireParams that you declare at start
|
|
59
|
+
const data = req.body.data;
|
|
60
|
+
/* data structure
|
|
61
|
+
data: {
|
|
62
|
+
parameter: {
|
|
63
|
+
lotNumber: number;
|
|
64
|
+
};
|
|
65
|
+
data: {
|
|
66
|
+
id: number;
|
|
67
|
+
name: string;
|
|
68
|
+
price: number;
|
|
69
|
+
}[];
|
|
70
|
+
}
|
|
71
|
+
*/
|
|
72
|
+
// also res.json(), you can only return structure like responseStructure that you declare at start
|
|
58
73
|
return res.json({
|
|
59
74
|
message: "",
|
|
60
75
|
status: "SUCCESS",
|
package/package.json
CHANGED
package/readme.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# GG-Express
|
|
2
|
+
|
|
3
|
+
this is express wrapper. that force method get,post,put,delete to have strong require req.query and req.body structure and generate apiConnector class file for using in any front end
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
- force express method get,post,put,delete to have strong require and response parameter
|
|
10
|
+
- generate strong static api url class combo with force require parameter and auto cast return type same as backend
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
You can install this package using npm or yarn:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
# Using npm
|
|
19
|
+
npm install gg-express
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
use case
|
|
23
|
+
```javascript
|
|
24
|
+
|
|
25
|
+
const app = express()
|
|
26
|
+
|
|
27
|
+
const ggapp = new GGExpress(app,
|
|
28
|
+
[
|
|
29
|
+
'./server/location-for-generating-file', # example path to backend
|
|
30
|
+
'./myapp/location-for-generating-file', # example path to frontend
|
|
31
|
+
])
|
|
32
|
+
|
|
33
|
+
// example force parameter
|
|
34
|
+
ggapp.post(
|
|
35
|
+
"/api/item",
|
|
36
|
+
{
|
|
37
|
+
requireParams: {
|
|
38
|
+
parameter: {
|
|
39
|
+
lotNumber: "number",
|
|
40
|
+
},
|
|
41
|
+
dataType: "arrayObject",
|
|
42
|
+
structure: {
|
|
43
|
+
id: "number",
|
|
44
|
+
name: "string",
|
|
45
|
+
price: "number",
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
responseStructure: {
|
|
49
|
+
parameter: { numberOfPeople: "number", itemName: "string" },
|
|
50
|
+
dataType: "arrayObject",
|
|
51
|
+
structure: {
|
|
52
|
+
id: "number",
|
|
53
|
+
name: "string",
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
(req, res, next) => {
|
|
58
|
+
// in body or query, you can access only requireParams that you declare at start
|
|
59
|
+
const data = req.body.data
|
|
60
|
+
//data structure
|
|
61
|
+
/*
|
|
62
|
+
data: {
|
|
63
|
+
parameter: {
|
|
64
|
+
lotNumber: number;
|
|
65
|
+
};
|
|
66
|
+
data: {
|
|
67
|
+
id: number;
|
|
68
|
+
name: string;
|
|
69
|
+
price: number;
|
|
70
|
+
}[];
|
|
71
|
+
}
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
// also res.json, you can access only return like responseStructure that you declare at start
|
|
75
|
+
return res.json({
|
|
76
|
+
message: "",
|
|
77
|
+
status: "SUCCESS",
|
|
78
|
+
data: [],
|
|
79
|
+
parameter: {
|
|
80
|
+
itemName: "",
|
|
81
|
+
numberOfPeople: 2,
|
|
82
|
+
},
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
app.listen(3000, () => {
|
|
88
|
+
ggapp.generateAPIFiles() // this will generate apiConnector class file that you can use in front end
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
```
|
package/src/GGApi.ts
CHANGED
package/src/test.ts
CHANGED
|
@@ -38,12 +38,13 @@ function run() {
|
|
|
38
38
|
{
|
|
39
39
|
requireParams: {
|
|
40
40
|
parameter: {
|
|
41
|
-
|
|
41
|
+
lotNumber: "number",
|
|
42
42
|
},
|
|
43
43
|
dataType: "arrayObject",
|
|
44
44
|
structure: {
|
|
45
45
|
id: "number",
|
|
46
46
|
name: "string",
|
|
47
|
+
price: "number",
|
|
47
48
|
},
|
|
48
49
|
},
|
|
49
50
|
responseStructure: {
|
|
@@ -56,7 +57,22 @@ function run() {
|
|
|
56
57
|
},
|
|
57
58
|
},
|
|
58
59
|
(req, res, next) => {
|
|
59
|
-
|
|
60
|
+
// in body or query, you can access only requireParams that you declare at start
|
|
61
|
+
const data = req.body.data
|
|
62
|
+
/* data structure
|
|
63
|
+
data: {
|
|
64
|
+
parameter: {
|
|
65
|
+
lotNumber: number;
|
|
66
|
+
};
|
|
67
|
+
data: {
|
|
68
|
+
id: number;
|
|
69
|
+
name: string;
|
|
70
|
+
price: number;
|
|
71
|
+
}[];
|
|
72
|
+
}
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
// also res.json(), you can only return structure like responseStructure that you declare at start
|
|
60
76
|
return res.json({
|
|
61
77
|
message: "",
|
|
62
78
|
status: "SUCCESS",
|