lieko-express 0.0.2 → 0.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.
- package/README.md +23 -63
- package/lieko-express.js +4 -1
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# **Lieko-express — A Modern, Minimal, REST API Framework for Node.js**
|
|
2
2
|
|
|
3
3
|
A lightweight, fast, and modern Node.js REST API framework built on top of the native `http` module. Zero external dependencies for core functionality.
|
|
4
4
|
|
|
@@ -10,6 +10,10 @@ A lightweight, fast, and modern Node.js REST API framework built on top of the n
|
|
|
10
10
|
|
|
11
11
|
[](https://opensource.org/licenses/MIT)
|
|
12
12
|
[](https://nodejs.org)
|
|
13
|
+
[](https://www.npmjs.com/package/lieko-express)
|
|
14
|
+
|
|
15
|
+
[](https://github.com/eiwSrvt/lieko-express)
|
|
16
|
+
[](https://discord.gg/EpgPqjvd)
|
|
13
17
|
|
|
14
18
|
|
|
15
19
|
|
|
@@ -102,7 +106,7 @@ app.get('/', (req, res) => {
|
|
|
102
106
|
app.listen(3000, () => {
|
|
103
107
|
console.log('Server running on port 3000');
|
|
104
108
|
});
|
|
105
|
-
|
|
109
|
+
```
|
|
106
110
|
|
|
107
111
|
## 🎯 Basic Usage
|
|
108
112
|
|
|
@@ -164,9 +168,13 @@ app.delete('/posts/:id', deletePost);
|
|
|
164
168
|
### Features
|
|
165
169
|
|
|
166
170
|
✔ Params automatically extracted
|
|
171
|
+
|
|
167
172
|
✔ Query auto-typed
|
|
173
|
+
|
|
168
174
|
✔ Body parsed and typed
|
|
175
|
+
|
|
169
176
|
✔ Wildcards available
|
|
177
|
+
|
|
170
178
|
✔ Trailing slashes handled intelligently
|
|
171
179
|
|
|
172
180
|
---
|
|
@@ -201,7 +209,7 @@ app.group('/api', auth, (api) => {
|
|
|
201
209
|
* You can nest indefinitely
|
|
202
210
|
* Works inside routers too
|
|
203
211
|
|
|
204
|
-
|
|
212
|
+
|
|
205
213
|
|
|
206
214
|
# 📦 Nested Routers
|
|
207
215
|
|
|
@@ -210,11 +218,11 @@ Routers are fully nestable:
|
|
|
210
218
|
```js
|
|
211
219
|
const { Router } = require('lieko-express');
|
|
212
220
|
|
|
213
|
-
const
|
|
221
|
+
const app = Router();
|
|
214
222
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
223
|
+
app.get('/', listUsers);
|
|
224
|
+
app.post('/', createUser);
|
|
225
|
+
app.get('/:id', getUser);
|
|
218
226
|
|
|
219
227
|
app.group('/api', auth, (api) => {
|
|
220
228
|
api.group('/admin', requireAdmin, (admin) => {
|
|
@@ -243,12 +251,13 @@ api.group(
|
|
|
243
251
|
}
|
|
244
252
|
);
|
|
245
253
|
```
|
|
246
|
-
|
|
254
|
+
✔ Router inherits middleware from its parent groups
|
|
255
|
+
|
|
256
|
+
✔ Paths automatically expanded
|
|
257
|
+
|
|
258
|
+
✔ Perfect for modular architecture
|
|
247
259
|
|
|
248
|
-
### ✔ Paths automatically expanded
|
|
249
260
|
|
|
250
|
-
### ✔ Perfect for modular architecture
|
|
251
|
-
---
|
|
252
261
|
# 🧩 API Versioning
|
|
253
262
|
|
|
254
263
|
With groups, versioning becomes trivial:
|
|
@@ -263,7 +272,6 @@ app.group('/api/v2', (v2) => {
|
|
|
263
272
|
});
|
|
264
273
|
```
|
|
265
274
|
|
|
266
|
-
---
|
|
267
275
|
|
|
268
276
|
### Query Parameters
|
|
269
277
|
|
|
@@ -291,7 +299,6 @@ app.get('/search', (req, res) => {
|
|
|
291
299
|
- `"true"` → `true` (boolean)
|
|
292
300
|
- `"false"` → `false` (boolean)
|
|
293
301
|
|
|
294
|
-
---
|
|
295
302
|
|
|
296
303
|
## 🔧 Middlewares
|
|
297
304
|
|
|
@@ -375,7 +382,6 @@ app.use(async (req, res, next) => {
|
|
|
375
382
|
});
|
|
376
383
|
```
|
|
377
384
|
|
|
378
|
-
---
|
|
379
385
|
|
|
380
386
|
# 🔍 Request Object
|
|
381
387
|
|
|
@@ -414,8 +420,6 @@ Lieko safely handles:
|
|
|
414
420
|
* IPv4-mapped IPv6
|
|
415
421
|
* Multiple proxies
|
|
416
422
|
|
|
417
|
-
---
|
|
418
|
-
|
|
419
423
|
|
|
420
424
|
# 🎯 Response Object (`res`)
|
|
421
425
|
|
|
@@ -434,7 +438,6 @@ Lieko enhances Node's native response object with convenient helper methods.
|
|
|
434
438
|
| `res.json(obj)` | Sends JSON with correct headers. |
|
|
435
439
|
| `res.end(body)` | Ends the response manually. |
|
|
436
440
|
|
|
437
|
-
---
|
|
438
441
|
|
|
439
442
|
# ✅ **High-Level Helpers**
|
|
440
443
|
|
|
@@ -447,7 +450,6 @@ Lieko enhances Node's native response object with convenient helper methods.
|
|
|
447
450
|
| `res.noContent()` | Sends status `204` with no body. |
|
|
448
451
|
| `res.paginated(payload)` | Standard API pagination output. |
|
|
449
452
|
|
|
450
|
-
---
|
|
451
453
|
|
|
452
454
|
# ❌ **Error Helpers**
|
|
453
455
|
|
|
@@ -466,8 +468,6 @@ Lieko enhances Node's native response object with convenient helper methods.
|
|
|
466
468
|
> { "success": false, "error": { "code": "...", "message": "..." } }
|
|
467
469
|
> ```
|
|
468
470
|
|
|
469
|
-
---
|
|
470
|
-
|
|
471
471
|
# 🧠 **Content-Type Helpers**
|
|
472
472
|
|
|
473
473
|
### **HTML**
|
|
@@ -482,7 +482,6 @@ Lieko enhances Node's native response object with convenient helper methods.
|
|
|
482
482
|
| -------------------------- | ------------------------------------- |
|
|
483
483
|
| `res.redirect(url, code?)` | Redirects the client (default `302`). |
|
|
484
484
|
|
|
485
|
-
---
|
|
486
485
|
|
|
487
486
|
# 📦 **Low-Level Output Controls**
|
|
488
487
|
|
|
@@ -515,8 +514,6 @@ res.paginated(items, page, limit, total);
|
|
|
515
514
|
* Error code → HTTP mapping
|
|
516
515
|
* String errors also supported (`res.error("Invalid user")`)
|
|
517
516
|
|
|
518
|
-
---
|
|
519
|
-
|
|
520
517
|
# 📦 Body Parsing
|
|
521
518
|
|
|
522
519
|
Lieko supports:
|
|
@@ -621,8 +618,6 @@ app.post('/upload', (req, res) => {
|
|
|
621
618
|
});
|
|
622
619
|
```
|
|
623
620
|
|
|
624
|
-
---
|
|
625
|
-
|
|
626
621
|
## ✅ Validation
|
|
627
622
|
|
|
628
623
|
### Built-in Validators
|
|
@@ -740,8 +735,6 @@ const userSchema = schema({
|
|
|
740
735
|
});
|
|
741
736
|
```
|
|
742
737
|
|
|
743
|
-
---
|
|
744
|
-
|
|
745
738
|
## **Boolean Example**
|
|
746
739
|
|
|
747
740
|
```js
|
|
@@ -758,8 +751,6 @@ Accepted:
|
|
|
758
751
|
true, false, "true", "false", 1, 0, "1", "0"
|
|
759
752
|
```
|
|
760
753
|
|
|
761
|
-
---
|
|
762
|
-
|
|
763
754
|
## **Email Example**
|
|
764
755
|
|
|
765
756
|
```js
|
|
@@ -771,8 +762,6 @@ const schema = schema({
|
|
|
771
762
|
});
|
|
772
763
|
```
|
|
773
764
|
|
|
774
|
-
---
|
|
775
|
-
|
|
776
765
|
## **Username with rules**
|
|
777
766
|
|
|
778
767
|
```js
|
|
@@ -787,8 +776,6 @@ const usernameSchema = schema({
|
|
|
787
776
|
});
|
|
788
777
|
```
|
|
789
778
|
|
|
790
|
-
---
|
|
791
|
-
|
|
792
779
|
## **Password strength**
|
|
793
780
|
|
|
794
781
|
```js
|
|
@@ -806,8 +793,6 @@ const passwordSchema = schema({
|
|
|
806
793
|
});
|
|
807
794
|
```
|
|
808
795
|
|
|
809
|
-
---
|
|
810
|
-
|
|
811
796
|
## **Multiple-choice fields**
|
|
812
797
|
|
|
813
798
|
```js
|
|
@@ -818,7 +803,6 @@ const roleSchema = schema({
|
|
|
818
803
|
});
|
|
819
804
|
```
|
|
820
805
|
|
|
821
|
-
---
|
|
822
806
|
|
|
823
807
|
## **Blacklist Example**
|
|
824
808
|
|
|
@@ -830,8 +814,6 @@ const schema = schema({
|
|
|
830
814
|
});
|
|
831
815
|
```
|
|
832
816
|
|
|
833
|
-
---
|
|
834
|
-
|
|
835
817
|
## **Starts / Ends With**
|
|
836
818
|
|
|
837
819
|
```js
|
|
@@ -842,11 +824,9 @@ const schema = schema({
|
|
|
842
824
|
});
|
|
843
825
|
```
|
|
844
826
|
|
|
845
|
-
---
|
|
846
|
-
|
|
847
827
|
# **Advanced Validation Examples**
|
|
848
828
|
|
|
849
|
-
|
|
829
|
+
|
|
850
830
|
|
|
851
831
|
## **Cross-field validation (matching passwords)**
|
|
852
832
|
|
|
@@ -863,7 +843,6 @@ const registerSchema = schema({
|
|
|
863
843
|
});
|
|
864
844
|
```
|
|
865
845
|
|
|
866
|
-
---
|
|
867
846
|
|
|
868
847
|
## Conditional Validation (depends on another field)
|
|
869
848
|
|
|
@@ -880,7 +859,6 @@ const orderSchema = schema({
|
|
|
880
859
|
});
|
|
881
860
|
```
|
|
882
861
|
|
|
883
|
-
---
|
|
884
862
|
|
|
885
863
|
## Dynamic rules EX: `age` required only if user is not admin
|
|
886
864
|
|
|
@@ -896,7 +874,6 @@ const schema = schema({
|
|
|
896
874
|
});
|
|
897
875
|
```
|
|
898
876
|
|
|
899
|
-
---
|
|
900
877
|
|
|
901
878
|
## **Date validation**
|
|
902
879
|
|
|
@@ -912,7 +889,6 @@ const eventSchema = schema({
|
|
|
912
889
|
});
|
|
913
890
|
```
|
|
914
891
|
|
|
915
|
-
---
|
|
916
892
|
|
|
917
893
|
# **Combining many validators**
|
|
918
894
|
|
|
@@ -928,7 +904,6 @@ const schema = schema({
|
|
|
928
904
|
});
|
|
929
905
|
```
|
|
930
906
|
|
|
931
|
-
---
|
|
932
907
|
|
|
933
908
|
# **Optional field + rules if provided**
|
|
934
909
|
|
|
@@ -945,7 +920,6 @@ const schema = schema({
|
|
|
945
920
|
If nickname is empty → no validation.
|
|
946
921
|
If present → must follow rules.
|
|
947
922
|
|
|
948
|
-
---
|
|
949
923
|
|
|
950
924
|
# **Example of validation error response**
|
|
951
925
|
|
|
@@ -1014,7 +988,6 @@ const orderSchema = schema({
|
|
|
1014
988
|
});
|
|
1015
989
|
```
|
|
1016
990
|
|
|
1017
|
-
---
|
|
1018
991
|
|
|
1019
992
|
## 🗂️ Routers
|
|
1020
993
|
|
|
@@ -1138,8 +1111,6 @@ app.use('/api/posts', postsRouter);
|
|
|
1138
1111
|
app.listen(3000);
|
|
1139
1112
|
```
|
|
1140
1113
|
|
|
1141
|
-
---
|
|
1142
|
-
|
|
1143
1114
|
## ⚠️ Error Handling
|
|
1144
1115
|
|
|
1145
1116
|
### Custom 404 Handler
|
|
@@ -1208,7 +1179,6 @@ res.error({ code: 'CUSTOM_ERROR', status: 418 });
|
|
|
1208
1179
|
}
|
|
1209
1180
|
```
|
|
1210
1181
|
|
|
1211
|
-
---
|
|
1212
1182
|
|
|
1213
1183
|
## 🔥 Advanced Examples
|
|
1214
1184
|
|
|
@@ -1551,7 +1521,6 @@ const requestLogger = (req, res, next) => {
|
|
|
1551
1521
|
app.use(requestLogger);
|
|
1552
1522
|
```
|
|
1553
1523
|
|
|
1554
|
-
---
|
|
1555
1524
|
|
|
1556
1525
|
## 🎯 Complete Application Example
|
|
1557
1526
|
|
|
@@ -1564,7 +1533,6 @@ See the [examples](./examples) directory for a full-featured application with:
|
|
|
1564
1533
|
- Middleware examples
|
|
1565
1534
|
- Comprehensive test suite
|
|
1566
1535
|
|
|
1567
|
-
---
|
|
1568
1536
|
|
|
1569
1537
|
# 📊 Performance Tips (Suite)
|
|
1570
1538
|
|
|
@@ -1575,7 +1543,6 @@ See the [examples](./examples) directory for a full-featured application with:
|
|
|
1575
1543
|
5. **Use reverse proxy headers correctly** (`trust proxy`) when hosting behind Nginx
|
|
1576
1544
|
6. **Disable console logs in production** or use a real logger with adjustable log levels
|
|
1577
1545
|
|
|
1578
|
-
---
|
|
1579
1546
|
|
|
1580
1547
|
## Debug & Introspection Tools
|
|
1581
1548
|
|
|
@@ -1720,7 +1687,6 @@ Lieko correctly handles:
|
|
|
1720
1687
|
* IPv4-mapped IPv6 (`::ffff:127.0.0.1`)
|
|
1721
1688
|
* Multi-proxy headers
|
|
1722
1689
|
|
|
1723
|
-
---
|
|
1724
1690
|
|
|
1725
1691
|
## 🧩 Internals & Architecture
|
|
1726
1692
|
|
|
@@ -1754,8 +1720,6 @@ This allows:
|
|
|
1754
1720
|
* Fast matching
|
|
1755
1721
|
|
|
1756
1722
|
|
|
1757
|
-
---
|
|
1758
|
-
|
|
1759
1723
|
## 🧱 Extending Lieko Express
|
|
1760
1724
|
|
|
1761
1725
|
Because the framework is intentionally small, you can easily extend it.
|
|
@@ -1786,8 +1750,6 @@ const timing = (req, res, next) => {
|
|
|
1786
1750
|
app.use(timing);
|
|
1787
1751
|
```
|
|
1788
1752
|
|
|
1789
|
-
---
|
|
1790
|
-
|
|
1791
1753
|
# 🔌 Plugins
|
|
1792
1754
|
|
|
1793
1755
|
A plugin is simply a function receiving `app`:
|
|
@@ -1799,7 +1761,6 @@ function myPlugin(app) {
|
|
|
1799
1761
|
|
|
1800
1762
|
myPlugin(app);
|
|
1801
1763
|
```
|
|
1802
|
-
---
|
|
1803
1764
|
|
|
1804
1765
|
## 🚀 Deploying Lieko Express
|
|
1805
1766
|
|
|
@@ -1862,7 +1823,7 @@ app.notFound((req, res) => {
|
|
|
1862
1823
|
|
|
1863
1824
|
Register a custom 500 handler.
|
|
1864
1825
|
|
|
1865
|
-
|
|
1826
|
+
|
|
1866
1827
|
|
|
1867
1828
|
## 🔍 Known Limitations
|
|
1868
1829
|
|
|
@@ -1876,7 +1837,6 @@ Because Lieko Express is minimalistic:
|
|
|
1876
1837
|
|
|
1877
1838
|
Future versions may address some of these.
|
|
1878
1839
|
|
|
1879
|
-
---
|
|
1880
1840
|
|
|
1881
1841
|
## 🤝 Contributing
|
|
1882
1842
|
|
|
@@ -1887,7 +1847,7 @@ Contributions are welcome!
|
|
|
1887
1847
|
3. Commit your changes
|
|
1888
1848
|
4. Open a pull request
|
|
1889
1849
|
|
|
1890
|
-
|
|
1850
|
+
|
|
1891
1851
|
|
|
1892
1852
|
## 📄 License
|
|
1893
1853
|
|
package/lieko-express.js
CHANGED
|
@@ -1086,9 +1086,12 @@ class LiekoExpress {
|
|
|
1086
1086
|
};
|
|
1087
1087
|
|
|
1088
1088
|
res.ok = (data, message) => {
|
|
1089
|
+
if (!res.statusCode || res.statusCode === 200) {
|
|
1090
|
+
res.status(200);
|
|
1091
|
+
}
|
|
1089
1092
|
const payload = { success: true, data };
|
|
1090
1093
|
if (message !== undefined) payload.message = message;
|
|
1091
|
-
return res.
|
|
1094
|
+
return res.json(payload);
|
|
1092
1095
|
};
|
|
1093
1096
|
res.success = res.ok;
|
|
1094
1097
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lieko-express",
|
|
3
|
-
"
|
|
3
|
+
"repository": {
|
|
4
|
+
"type": "git",
|
|
5
|
+
"url": "https://github.com/eiwSrvt/lieko-express"
|
|
6
|
+
},
|
|
7
|
+
"homepage": "https://github.com/eiwSrvt/lieko-express",
|
|
8
|
+
"version": "0.0.3",
|
|
4
9
|
"description": "Lieko-express — A Modern, Minimal, REST API Framework for Node.js",
|
|
5
10
|
"main": "lieko-express.js",
|
|
6
11
|
"scripts": {
|
|
@@ -14,4 +19,4 @@
|
|
|
14
19
|
"lieko-express.js",
|
|
15
20
|
"README.md"
|
|
16
21
|
]
|
|
17
|
-
}
|
|
22
|
+
}
|