gg-express 1.0.26 → 1.0.27

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/package.json +1 -1
  2. package/readme.md +86 -68
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gg-express",
3
- "version": "1.0.26",
3
+ "version": "1.0.27",
4
4
  "description": "",
5
5
  "main": "dist/GGExpress.js",
6
6
  "scripts": {
package/readme.md CHANGED
@@ -1,14 +1,30 @@
1
1
  # GG-Express
2
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
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
6
 
7
+ - Enforces required request (`req.query` and `req.body`) and response parameter types for `GET`, `POST`, `PUT`, and `DELETE` methods in Express.
8
+ - Automatically generates a static API URL class that strongly types parameters and auto-casts return types to match the backend's response structure.
9
+ - Simplifies integrating strong typing between back-end and front-end.
6
10
 
7
11
 
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
12
+ ## Key Points
13
+
14
+ - Strict Parameter Enforcement: GG-Express ensures that only the declared parameters are accessible in your req.body or req.query.
15
+
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
+
22
+ Install the package using either `npm` or `yarn`:
23
+
24
+ ### Using npm:
11
25
 
26
+ ```bash
27
+ npm install gg-express
12
28
 
13
29
  ## Installation
14
30
 
@@ -22,70 +38,72 @@ npm install gg-express
22
38
  use case
23
39
  ```javascript
24
40
 
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
- },
41
+ const express = require('express');
42
+ const GGExpress = require('gg-express'); // Import GG-Express
43
+ const app = express();
44
+
45
+ // Initialize GG-Express with backend and frontend file paths
46
+ const ggapp = new GGExpress(app, [
47
+ './server/location-for-generating-file', // Path to generate backend file
48
+ './myapp/location-for-generating-file', // Path to generate frontend file
49
+ ]);
50
+
51
+ // Example of a POST request with enforced parameters
52
+ ggapp.post(
53
+ "/api/item",
54
+ {
55
+ requireParams: {
56
+ parameter: { lotNumber: "number" },
57
+ dataType: "arrayObject",
58
+ structure: {
59
+ id: "number",
60
+ name: "string",
61
+ price: "number",
47
62
  },
48
- responseStructure: {
49
- parameter: { numberOfPeople: "number", itemName: "string" },
50
- dataType: "arrayObject",
51
- structure: {
52
- id: "number",
53
- name: "string",
54
- },
63
+ },
64
+ responseStructure: {
65
+ parameter: { numberOfPeople: "number", itemName: "string" },
66
+ dataType: "arrayObject",
67
+ structure: {
68
+ id: "number",
69
+ name: "string",
55
70
  },
56
71
  },
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
- ```
72
+ },
73
+ (req, res, next) => {
74
+ // You can only access the required parameters declared above
75
+ const data = req.body.data;
76
+
77
+ // Expected data structure:
78
+ // data: {
79
+ // parameter: {
80
+ // lotNumber: number;
81
+ // };
82
+ // data: [{
83
+ // id: number;
84
+ // name: string;
85
+ // price: number;
86
+ // }];
87
+ // }
88
+
89
+ // Response structure also follows the predefined format
90
+ return res.json({
91
+ message: "",
92
+ status: "SUCCESS",
93
+ data: [],
94
+ parameter: {
95
+ itemName: "",
96
+ numberOfPeople: 2,
97
+ },
98
+ });
99
+ }
100
+ );
101
+
102
+ // Start the server and generate the API files
103
+ app.listen(3000, () => {
104
+ ggapp.generateAPIFiles(); // Generates the apiConnector class for front-end use
105
+ });
106
+
107
+
108
+ ```
109
+