burger-api 0.0.35 → 0.0.37
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/LICENSE +21 -0
- package/README.md +54 -41
- package/dist/src/core/router.js +1 -1
- package/dist/src/core/server.js +1 -1
- package/package.json +82 -76
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Isfhan Ahmed
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,61 +1,60 @@
|
|
|
1
|
-
# burger-api [](https://github.com/isfhan/burger-api)
|
|
1
|
+
# 🍔 burger-api [](https://github.com/isfhan/burger-api) [](LICENSE) [](https://bun.sh)
|
|
2
2
|
|
|
3
|
-
**burger-api** is a modern, open source API framework built on [Bun.js](https://bun.sh). It combines the simplicity of file-based routing
|
|
3
|
+
**burger-api** is a modern, open source API framework built on [Bun.js](https://bun.sh). It combines the simplicity of file-based routing with powerful features like built-in middleware, Zod-based schema validation, and automatic OpenAPI generation. Designed for high performance and ease-of-use, burger-api leverages Bun's native modules to deliver blazing-fast API responses while keeping your codebase clean and maintainable.
|
|
4
4
|
|
|
5
5
|
**This project is under active development and should not be used in production yet.**
|
|
6
6
|
|
|
7
|
-
## Overview
|
|
7
|
+
## 🚀 Overview
|
|
8
8
|
|
|
9
9
|
burger-api is built to offer a robust developer experience through:
|
|
10
10
|
|
|
11
|
-
- **Bun-Native Performance:**
|
|
12
|
-
Leverages Bun
|
|
11
|
+
- ⚡ **Bun-Native Performance:**
|
|
12
|
+
Leverages Bun's high-performance HTTP server.
|
|
13
13
|
|
|
14
|
-
- **File-Based Routing:**
|
|
15
|
-
Automatically registers API
|
|
14
|
+
- 📁 **File-Based Routing:**
|
|
15
|
+
Automatically registers API routes from your file structure using a clear naming convention.
|
|
16
16
|
|
|
17
|
-
- **Middleware Architecture:**
|
|
17
|
+
- 🔄 **Middleware Architecture:**
|
|
18
18
|
Supports both global and route-specific middleware with a familiar `req, res, next` pattern.
|
|
19
19
|
|
|
20
|
-
- **Type-Safe Validation:**
|
|
20
|
+
- ✅ **Type-Safe Validation:**
|
|
21
21
|
Utilizes Zod for request validation, ensuring full type safety and automatic error reporting.
|
|
22
22
|
|
|
23
|
-
- **Automatic OpenAPI Generation:**
|
|
23
|
+
- 📚 **Automatic OpenAPI Generation:**
|
|
24
24
|
Generates a complete OpenAPI 3.0 specification (with support for tags, summaries, descriptions, operationId, deprecated status, externalDocs, and more) directly from your routes and Zod schemas.
|
|
25
25
|
|
|
26
|
-
- **Swagger UI Integration:**
|
|
26
|
+
- 🔍 **Swagger UI Integration:**
|
|
27
27
|
Provides an out-of-the-box Swagger UI endpoint for interactive API documentation.
|
|
28
28
|
|
|
29
|
-
## Features
|
|
29
|
+
## ✨ Features
|
|
30
30
|
|
|
31
31
|
### Core Features
|
|
32
32
|
|
|
33
|
-
- **Bun-Native HTTP Server:**
|
|
34
|
-
Built on Bun
|
|
33
|
+
- ⚡ **Bun-Native HTTP Server:**
|
|
34
|
+
Built on Bun's native APIs for exceptional performance.
|
|
35
35
|
|
|
36
|
-
- **File-Based Routing Engine:**
|
|
36
|
+
- 📁 **File-Based Routing Engine:**
|
|
37
37
|
Automatically scans directories to register routes.
|
|
38
38
|
|
|
39
39
|
- Supports dynamic routes via folder names like `[id]` for `/api/product/:id`.
|
|
40
|
-
- Differentiates between API routes (`route.ts`) and page routes (`page.ts`).
|
|
41
40
|
|
|
42
|
-
- **Request & Response Enhancements:**
|
|
41
|
+
- 🛠️ **Request & Response Enhancements:**
|
|
43
42
|
|
|
44
43
|
- `BurgerRequest` extends the native Request to include query, params, and validated data.
|
|
45
44
|
- `BurgerResponse` provides methods to set headers, status, and build responses (JSON, text, HTML, redirects, files).
|
|
46
45
|
|
|
47
|
-
- **Middleware System:**
|
|
46
|
+
- 🔄 **Middleware System:**
|
|
48
47
|
|
|
49
48
|
- **Global Middleware:** Runs on every request.
|
|
50
49
|
- **Route-Specific Middleware:** Defined in individual route files.
|
|
51
50
|
- **Validation Middleware:** Automatically validates request data using Zod schemas exported from routes.
|
|
52
51
|
|
|
53
|
-
- **Zod-Based Schema Validation:**
|
|
52
|
+
- ✅ **Zod-Based Schema Validation:**
|
|
54
53
|
Automatically validates request params, query, and body using Zod.
|
|
55
54
|
|
|
56
55
|
- Supports preprocessing (e.g., converting URL parameters from string to number).
|
|
57
56
|
|
|
58
|
-
- **Automatic OpenAPI Specification Generation:**
|
|
57
|
+
- 📚 **Automatic OpenAPI Specification Generation:**
|
|
59
58
|
Generates an OpenAPI 3.0 document using route metadata and Zod schemas.
|
|
60
59
|
|
|
61
60
|
- **OpenAPI Options:**
|
|
@@ -63,10 +62,22 @@ burger-api is built to offer a robust developer experience through:
|
|
|
63
62
|
- Per-route metadata (summary, description, tags, operationId, deprecated, externalDocs)
|
|
64
63
|
- Auto-generated parameters and requestBody schemas (using `zod-to-json-schema` for detailed inline JSON schema definitions)
|
|
65
64
|
|
|
66
|
-
- **Swagger UI Integration:**
|
|
65
|
+
- 🔍 **Swagger UI Integration:**
|
|
67
66
|
Provides a `/docs` endpoint serving an interactive Swagger UI that reads from `/openapi.json`.
|
|
68
67
|
|
|
69
|
-
##
|
|
68
|
+
## 🎯 What's Coming Next?
|
|
69
|
+
|
|
70
|
+
We're enhancing burger-api to make it even more powerful! While our core focus remains on building fast, type-safe APIs, we're adding the ability to serve simple pages when needed:
|
|
71
|
+
|
|
72
|
+
### 🎨 Simple Page Serving (Coming Soon!)
|
|
73
|
+
- Optional page serving capability for simple views
|
|
74
|
+
- Perfect for API documentation, admin panels, or simple dashboards
|
|
75
|
+
- Not meant to replace full-stack frameworks like Next.js
|
|
76
|
+
- For complex frontend applications, we recommend using dedicated frontend frameworks
|
|
77
|
+
|
|
78
|
+
Stay tuned for updates as we continue to build and improve burger-api! We're committed to making it the best API framework for Bun.js.
|
|
79
|
+
|
|
80
|
+
## 📦 Installation
|
|
70
81
|
|
|
71
82
|
Install burger-api via bun:
|
|
72
83
|
|
|
@@ -74,12 +85,12 @@ Install burger-api via bun:
|
|
|
74
85
|
bun add burger-api
|
|
75
86
|
```
|
|
76
87
|
|
|
77
|
-
## How to Use burger-api
|
|
88
|
+
## 🚀 How to Use burger-api
|
|
78
89
|
|
|
79
90
|
### **Basic Usage Example**
|
|
80
91
|
|
|
81
92
|
```ts
|
|
82
|
-
import { Burger
|
|
93
|
+
import { Burger } from "burger-api";
|
|
83
94
|
|
|
84
95
|
// Global middleware example: a simple logger.
|
|
85
96
|
const globalLogger = async (req, res, next) => {
|
|
@@ -88,11 +99,11 @@ const globalLogger = async (req, res, next) => {
|
|
|
88
99
|
};
|
|
89
100
|
|
|
90
101
|
const burger = new Burger({
|
|
91
|
-
apiDir: setDir(__dirname, "api"),
|
|
92
102
|
title: "My Custom API",
|
|
93
103
|
description: "Custom API with auto-generated docs and validation",
|
|
94
|
-
|
|
104
|
+
apiDir: "api",
|
|
95
105
|
globalMiddleware: [globalLogger],
|
|
106
|
+
version: "1.0.0",
|
|
96
107
|
});
|
|
97
108
|
|
|
98
109
|
// Start the server on port 4000 with a callback
|
|
@@ -103,10 +114,10 @@ burger.serve(4000, (port) => {
|
|
|
103
114
|
|
|
104
115
|
### **File-Based Routing Examples**
|
|
105
116
|
|
|
106
|
-
- **Static API Route:**
|
|
117
|
+
- 📄 **Static API Route:**
|
|
107
118
|
Place a file at `src/api/route.ts` to handle the root API endpoint (e.g., `/api`).
|
|
108
119
|
|
|
109
|
-
- **Dynamic API Route:**
|
|
120
|
+
- 🔄 **Dynamic API Route:**
|
|
110
121
|
For routes with dynamic segments, create folders with square brackets. For example:
|
|
111
122
|
```
|
|
112
123
|
src/api/product/
|
|
@@ -194,32 +205,34 @@ export async function POST(req: BurgerRequest, res: BurgerResponse) {
|
|
|
194
205
|
|
|
195
206
|
### **API Documentation Endpoints**
|
|
196
207
|
|
|
197
|
-
- **OpenAPI JSON:**
|
|
208
|
+
- 📚 **OpenAPI JSON:**
|
|
198
209
|
Access `http://localhost:4000/openapi.json` to view the auto-generated OpenAPI specification.
|
|
199
210
|
|
|
200
|
-
- **Swagger UI:**
|
|
211
|
+
- 🔍 **Swagger UI:**
|
|
201
212
|
Access `http://localhost:4000/docs` to view interactive API documentation via Swagger UI.
|
|
202
213
|
|
|
203
|
-
## Contributing
|
|
214
|
+
## 🤝 Contributing
|
|
215
|
+
|
|
216
|
+
We welcome contributions from the community! If you have suggestions or improvements, please open an issue or submit a pull request. Let's build something amazing together.
|
|
204
217
|
|
|
205
|
-
|
|
218
|
+
## 📄 License
|
|
206
219
|
|
|
207
|
-
|
|
220
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
208
221
|
|
|
209
|
-
|
|
222
|
+
The MIT License is a permissive license that is short and to the point. It lets people do anything they want with your code as long as they provide attribution back to you and don't hold you liable.
|
|
210
223
|
|
|
211
|
-
## FAQs & Additional Resources
|
|
224
|
+
## ❓ FAQs & Additional Resources
|
|
212
225
|
|
|
213
|
-
- **How do I add custom middleware?**
|
|
226
|
+
- 🔄 **How do I add custom middleware?**
|
|
214
227
|
You can pass an array of global middleware in the Burger options or export route-specific middleware in your route files.
|
|
215
228
|
|
|
216
|
-
- **How does file-based routing work?**
|
|
217
|
-
Place your route files under `src/api/`
|
|
229
|
+
- 📁 **How does file-based routing work?**
|
|
230
|
+
Place your route files under `src/api/` or just `/api` using folder and file naming conventions (e.g., `[id]` for dynamic routes).
|
|
218
231
|
|
|
219
|
-
- **How is validation handled?**
|
|
232
|
+
- ✅ **How is validation handled?**
|
|
220
233
|
burger-api uses Zod for schema validation. Define your schemas in your route files and they are automatically used to validate incoming requests.
|
|
221
234
|
|
|
222
|
-
- **How can I customize the OpenAPI documentation?**
|
|
235
|
+
- 📚 **How can I customize the OpenAPI documentation?**
|
|
223
236
|
Override the default auto-generated summaries, descriptions, tags, and operationIds by exporting an `openapi` object in your route files.
|
|
224
237
|
|
|
225
|
-
_burger-api_ aims to revolutionize your API development experience with simplicity, speed, and cutting-edge features. Happy coding!
|
|
238
|
+
_burger-api_ aims to revolutionize your API development experience with simplicity, speed, and cutting-edge features. Happy coding! 🚀
|
package/dist/src/core/router.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { readdirSync } from "fs";
|
|
3
3
|
import * as path from "path";
|
|
4
4
|
// Import utils
|
|
5
|
-
import { cleanPrefix, normalizePath } from "
|
|
5
|
+
import { cleanPrefix, normalizePath } from "../utils/index.js";
|
|
6
6
|
/**
|
|
7
7
|
* Router class for handling file-based routing.
|
|
8
8
|
* Loads routes from a directory structure and matches requests to the appropriate route handlers.
|
package/dist/src/core/server.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { HttpRequest } from "./request.js";
|
|
3
3
|
import { HttpResponse } from "./response.js";
|
|
4
4
|
// Import stuff from utils
|
|
5
|
-
import { errorResponse } from "
|
|
5
|
+
import { errorResponse } from "../utils/error.js";
|
|
6
6
|
export class Server {
|
|
7
7
|
options;
|
|
8
8
|
server = null;
|
package/package.json
CHANGED
|
@@ -1,76 +1,82 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "burger-api",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"author": "Isfhan Ahmed",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"module": "dist/src/index.js",
|
|
7
|
-
"types": "dist/src/index.d.ts",
|
|
8
|
-
"files": [
|
|
9
|
-
"dist"
|
|
10
|
-
],
|
|
11
|
-
"scripts": {
|
|
12
|
-
"typecheck": "tsc --noEmit",
|
|
13
|
-
"build": "tsc --project tsconfig.build.json",
|
|
14
|
-
"test": "bun test",
|
|
15
|
-
"dev": "bun run examples/native-server/index.ts"
|
|
16
|
-
},
|
|
17
|
-
"keywords": [
|
|
18
|
-
"burger-api",
|
|
19
|
-
"burger-api-framework",
|
|
20
|
-
"bun",
|
|
21
|
-
"bunjs",
|
|
22
|
-
"bun-framework",
|
|
23
|
-
"fast-backend",
|
|
24
|
-
"javascript-backend",
|
|
25
|
-
"high-performance",
|
|
26
|
-
"esm",
|
|
27
|
-
"typescript",
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"backend
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"backend-
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
"
|
|
75
|
-
}
|
|
76
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "burger-api",
|
|
3
|
+
"version": "0.0.37",
|
|
4
|
+
"author": "Isfhan Ahmed",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"module": "dist/src/index.js",
|
|
7
|
+
"types": "dist/src/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"typecheck": "tsc --noEmit",
|
|
13
|
+
"build": "tsc --project tsconfig.build.json",
|
|
14
|
+
"test": "bun test",
|
|
15
|
+
"dev": "bun run examples/native-server/index.ts"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"burger-api",
|
|
19
|
+
"burger-api-framework",
|
|
20
|
+
"bun",
|
|
21
|
+
"bunjs",
|
|
22
|
+
"bun-framework",
|
|
23
|
+
"fast-backend",
|
|
24
|
+
"javascript-backend",
|
|
25
|
+
"high-performance",
|
|
26
|
+
"esm",
|
|
27
|
+
"typescript",
|
|
28
|
+
"openapi",
|
|
29
|
+
"swagger-ui",
|
|
30
|
+
"declarative-routing",
|
|
31
|
+
"api-framework",
|
|
32
|
+
"modern-backend",
|
|
33
|
+
"backend-framework",
|
|
34
|
+
"server",
|
|
35
|
+
"bun-native",
|
|
36
|
+
"js-backend",
|
|
37
|
+
"fast-api",
|
|
38
|
+
"scalable-backend",
|
|
39
|
+
"backend-development",
|
|
40
|
+
"modern-api",
|
|
41
|
+
"api-development",
|
|
42
|
+
"backend-engine",
|
|
43
|
+
"efficient",
|
|
44
|
+
"minimalist-backend",
|
|
45
|
+
"bun-powered",
|
|
46
|
+
"open-source",
|
|
47
|
+
"typescript-backend",
|
|
48
|
+
"performance",
|
|
49
|
+
"rapid-development",
|
|
50
|
+
"web-framework",
|
|
51
|
+
"api-server",
|
|
52
|
+
"dynamic-routing",
|
|
53
|
+
"backend-routing",
|
|
54
|
+
"extensible",
|
|
55
|
+
"modular",
|
|
56
|
+
"declarative-api",
|
|
57
|
+
"lightweight",
|
|
58
|
+
"contemporary-backend",
|
|
59
|
+
"fast-javascript",
|
|
60
|
+
"bun-js-framework",
|
|
61
|
+
"bun-backend"
|
|
62
|
+
],
|
|
63
|
+
"license": "MIT",
|
|
64
|
+
"repository": {
|
|
65
|
+
"type": "git",
|
|
66
|
+
"url": "git+https://github.com/isfhan/burger-api.git"
|
|
67
|
+
},
|
|
68
|
+
"bugs": {
|
|
69
|
+
"url": "https://github.com/isfhan/burger-api/issues"
|
|
70
|
+
},
|
|
71
|
+
"homepage": "https://github.com/isfhan/burger-api#readme",
|
|
72
|
+
"dependencies": {
|
|
73
|
+
"zod": "^3.24.2",
|
|
74
|
+
"zod-to-json-schema": "^3.24.2"
|
|
75
|
+
},
|
|
76
|
+
"devDependencies": {
|
|
77
|
+
"@types/bun": "latest"
|
|
78
|
+
},
|
|
79
|
+
"peerDependencies": {
|
|
80
|
+
"typescript": "^5.0.0"
|
|
81
|
+
}
|
|
82
|
+
}
|