gg-express 1.0.43 → 1.0.44
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/package.json +13 -3
- package/readme.md +60 -40
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gg-express",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.44",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/GGExpress.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "npm version patch && tsc",
|
|
8
8
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
9
|
},
|
|
10
|
-
"author": "",
|
|
10
|
+
"author": "goomgum",
|
|
11
11
|
"license": "ISC",
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@types/axios": "^0.14.0",
|
|
@@ -20,5 +20,15 @@
|
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/express": "^5.0.0"
|
|
23
|
-
}
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"express",
|
|
26
|
+
"typescript",
|
|
27
|
+
"api",
|
|
28
|
+
"wrapper",
|
|
29
|
+
"type-safe",
|
|
30
|
+
"backend",
|
|
31
|
+
"frontend",
|
|
32
|
+
"api-connector"
|
|
33
|
+
]
|
|
24
34
|
}
|
package/readme.md
CHANGED
|
@@ -1,39 +1,37 @@
|
|
|
1
|
-
# GG-Express
|
|
1
|
+
# 🚀 GG-Express
|
|
2
2
|
|
|
3
3
|
**GG-Express** is an Express.js wrapper that enforces strong type requirements for `GET`, `POST`, `PUT`, and `DELETE` methods. It ensures that `req.query` and `req.body` follow strict structure definitions and automatically generates an `apiConnector` class file for easy use in front-end development.
|
|
4
4
|
|
|
5
|
-
## Features
|
|
5
|
+
## ✨ Features
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
- Automatically
|
|
9
|
-
- Simplifies
|
|
7
|
+
- **Strict Type Enforcement**: Ensures that `req.query` and `req.body` follow the declared types.
|
|
8
|
+
- **Auto-Generated API Connector**: Automatically creates a static API class for strongly-typed parameters.
|
|
9
|
+
- **Seamless Front-End Integration**: Simplifies the connection between the back-end and front-end by enforcing consistency.
|
|
10
10
|
|
|
11
|
+
## 🔑 Key Points
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
- **Strict Parameter Enforcement**: GG-Express ensures only the declared parameters are accessible in `req.body` or `req.query`.
|
|
14
|
+
- **Type-Safe Responses**: Ensures that the backend responds with a structure that matches front-end expectations.
|
|
15
|
+
- **API Connector Generation**: It automatically generates a type-safe API connector class file for the front-end.
|
|
13
16
|
|
|
14
|
-
|
|
17
|
+
## 🛠 Installation
|
|
15
18
|
|
|
16
|
-
- Type-Safe Responses: You can only return data that follows the predefined responseStructure, improving consistency between backend and frontend.
|
|
17
|
-
|
|
18
|
-
- API Connector Generation: It automatically generates an API connector class file for your front-end, making API calls more reliable and type-safe.
|
|
19
|
-
|
|
20
|
-
## Installation
|
|
21
19
|
```bash
|
|
22
20
|
npm install gg-express
|
|
23
21
|
```
|
|
24
22
|
|
|
25
|
-
|
|
26
|
-
```javascript
|
|
23
|
+
🧑💻 Use Case in Backend
|
|
27
24
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
```typescript
|
|
26
|
+
import express from "express"
|
|
27
|
+
import GGExpress from "gg-express"
|
|
28
|
+
const app = express()
|
|
31
29
|
|
|
32
30
|
// Initialize GG-Express with backend and frontend file paths
|
|
33
31
|
const ggapp = new GGExpress(app, [
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
])
|
|
32
|
+
"./server/output-path-for-apiConnector.ts", // Path to generate apiConnector.ts backend file
|
|
33
|
+
"./myapp/output-path-for-apiConnector.ts", // Path to generate apiConnector.ts frontend file
|
|
34
|
+
])
|
|
37
35
|
|
|
38
36
|
// Example of a POST request with enforced parameters
|
|
39
37
|
ggapp.post(
|
|
@@ -58,22 +56,10 @@ ggapp.post(
|
|
|
58
56
|
},
|
|
59
57
|
},
|
|
60
58
|
(req, res, next) => {
|
|
61
|
-
//
|
|
62
|
-
const data = req.body.data
|
|
63
|
-
|
|
64
|
-
//
|
|
65
|
-
// data: {
|
|
66
|
-
// parameter: {
|
|
67
|
-
// lotNumber: number;
|
|
68
|
-
// };
|
|
69
|
-
// data: [{
|
|
70
|
-
// id: number;
|
|
71
|
-
// name: string;
|
|
72
|
-
// price: number;
|
|
73
|
-
// }];
|
|
74
|
-
// }
|
|
75
|
-
|
|
76
|
-
// Response structure also follows the predefined format
|
|
59
|
+
// Access only the required parameters declared above
|
|
60
|
+
const data = req.body.data
|
|
61
|
+
|
|
62
|
+
// Response structure follows the predefined format
|
|
77
63
|
return res.json({
|
|
78
64
|
message: "",
|
|
79
65
|
status: "SUCCESS",
|
|
@@ -82,15 +68,49 @@ ggapp.post(
|
|
|
82
68
|
itemName: "",
|
|
83
69
|
numberOfPeople: 2,
|
|
84
70
|
},
|
|
85
|
-
})
|
|
71
|
+
})
|
|
86
72
|
}
|
|
87
|
-
)
|
|
73
|
+
)
|
|
88
74
|
|
|
89
75
|
// Start the server and generate the API files
|
|
90
76
|
app.listen(3000, () => {
|
|
91
|
-
ggapp.generateAPIFiles()
|
|
92
|
-
})
|
|
77
|
+
ggapp.generateAPIFiles() // Generates the apiConnector class for front-end use
|
|
78
|
+
})
|
|
79
|
+
```
|
|
93
80
|
|
|
81
|
+
📲 Use Case in Frontend
|
|
82
|
+
• The apiConnector.ts file will be automatically generated by the GGExpress class you configured in the backend
|
|
94
83
|
|
|
84
|
+
```typescript
|
|
85
|
+
import GGApi from "apiConnector.ts"
|
|
86
|
+
|
|
87
|
+
const api = new GGApi()
|
|
88
|
+
const response = await api.post("/api/item", {
|
|
89
|
+
parameter: {
|
|
90
|
+
lotNumber: 2,
|
|
91
|
+
},
|
|
92
|
+
data: [
|
|
93
|
+
{
|
|
94
|
+
id: 1032,
|
|
95
|
+
name: "machete",
|
|
96
|
+
price: 4599,
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
})
|
|
100
|
+
console.log(response.data)
|
|
101
|
+
// Expected data structure:
|
|
102
|
+
// parameter: { numberOfPeople: number, itemName: string },
|
|
103
|
+
// structure: {
|
|
104
|
+
// id: number,
|
|
105
|
+
// name: string,
|
|
106
|
+
// }[],
|
|
107
|
+
// }
|
|
95
108
|
```
|
|
96
109
|
|
|
110
|
+
## 🔑 Keywords
|
|
111
|
+
|
|
112
|
+
- Express.js
|
|
113
|
+
- TypeScript
|
|
114
|
+
- API wrapper
|
|
115
|
+
- Type-safe API
|
|
116
|
+
- Backend-frontend integration
|