diff --git a/.gemini/settings.json b/.gemini/settings.json deleted file mode 100644 index 9bd4773..0000000 --- a/.gemini/settings.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "version": "1.0", - "project": { - "name": "BanglaCode", - "type": "Programming Language Interpreter", - "language": "Go", - "runtime": "Go ≥1.20" - }, - "context": { - "fileName": ["GEMINI.md", "SYNTAX.md"], - "hierarchical": true - }, - "tools": { - "enabled": ["codeSearch", "fileOperations", "shellCommands"] - } -} diff --git a/Documentation/app/docs/http-routing/page.tsx b/Documentation/app/docs/http-routing/page.tsx index 6226d15..3605e86 100644 --- a/Documentation/app/docs/http-routing/page.tsx +++ b/Documentation/app/docs/http-routing/page.tsx @@ -426,6 +426,229 @@ pathao authRouter; // Always export your router`}
+

Path Parameters

+

Use :name segments in route paths. Values are available in req["params"] as a MAP.

+
+{`dhoro app = router_banao(); + +// Single param: /users/123 +app.ana("/users/:id", kaj(req, res) { + dhoro id = req["params"]["id"]; + json_uttor(res, {"user_id": id}); +}); + +// Multiple params: /posts/42/comments/7 +app.ana("/posts/:pid/comments/:cid", kaj(req, res) { + dhoro pid = req["params"]["pid"]; + dhoro cid = req["params"]["cid"]; + json_uttor(res, {"post": pid, "comment": cid}); +});`} +
+ +
+ +

Query String Parsing

+

req["query"] is a parsed MAP. Use req["query_raw"] for the raw string.

+
+{`// GET /search?q=hello&page=2 +app.ana("/search", kaj(req, res) { + dhoro term = req["query"]["q"]; // "hello" + dhoro page = req["query"]["page"]; // "2" + json_uttor(res, {"term": term, "page": page}); +});`} +
+ +
+ +

Auto JSON Body Parsing

+

When the request has Content-Type: application/json, req["json"] is auto-parsed. Otherwise it is khali.

+
+{`app.pathano("/users", kaj(req, res) { + dhoro user = req["json"]; // auto-parsed MAP — no json_poro() needed + dekho("Name:", user["name"]); + json_uttor(res, {"created": sotti}, 201); +});`} +
+ +
+ +

Middleware (majhe - মাঝে)

+

Runs before every route handler. Call agorao() (আগাও = go forward) to pass to the next layer.

+
+{`dhoro app = router_banao(); + +// Logging middleware +app.majhe(kaj(req, res, agorao) { + dekho(req["method"], req["path"]); + agorao(); // must call to continue! +}); + +// Auth middleware +app.majhe(kaj(req, res, agorao) { + jodi (req["headers"]["Authorization"] == khali) { + json_uttor(res, {"error": "Unauthorized"}, 401); + ferao; // stop here — don't call agorao() + } + agorao(); +}); + +app.ana("/", kaj(req, res) { + uttor(res, "Protected page"); +});`} +
+ +
+ +

CORS (cors_chharpao - ছাড়পাও)

+

Enables Cross-Origin Resource Sharing. Call before defining routes.

+
+{`dhoro app = router_banao(); + +cors_chharpao(app); // allow all origins (default) + +// Custom options +cors_chharpao(app, { + "origin": "https://myapp.com", + "methods": "GET,POST,PUT,DELETE" +});`} +
+ +
+ +

Static File Serving (file_dao - ফাইল দাও)

+
+{`dhoro app = router_banao(); +file_dao(app, "/public", "./static_files"); +// GET /public/style.css → serves ./static_files/style.css`} +
+ +
+ +

Cookie Handling

+

Read cookies from req["kukis"]. Set cookies with kuki_rakho() (কুকি রাখো).

+
+{`app.ana("/profile", kaj(req, res) { + dhoro sessionToken = req["kukis"]["session"]; + json_uttor(res, {"token": sessionToken}); +}); + +app.pathano("/login", kaj(req, res) { + // Basic cookie + kuki_rakho(res, "session", "token123"); + + // With options + kuki_rakho(res, "session", "token123", { + "httpOnly": sotti, + "maxAge": 86400, + "sameSite": "Lax", + "secure": sotti + }); + json_uttor(res, {"ok": sotti}); +});`} +
+ +
+ +

Redirect (ghurao - ঘোরাও)

+
+{`app.ana("/old-page", kaj(req, res) { + ghurao(res, "/new-page"); // 302 Found +}); + +app.ana("/moved", kaj(req, res) { + ghurao(res, "/permanent", 301); // 301 Moved Permanently +});`} +
+ +
+ +

HTML File Response (html_uttor - HTML উত্তর)

+
+{`app.ana("/", kaj(req, res) { + html_uttor(res, "./views/index.html"); +});`} +
+ +
+ +

Error Middleware (bhul_sambhalo - ভুল সামলাও)

+

Catches errors returned by route handlers. Register after all routes.

+
+{`bhul_sambhalo(app, kaj(err, req, res) { + json_uttor(res, {"error": err["message"]}, 500); +});`} +
+ +
+ +

Performance Features

+
+{`dhoro app = router_banao(); + +goti_shima(app, 100, 60); // rate limit: 100 req/min per IP (গতি সীমা) +sankochon_chalu(app); // gzip compression (সংকোচন চালু) +somoy_shima(app, 30); // 30-second timeout (সময় সীমা) +akaar_shima(app, 1048576); // 1 MB body limit (আকার সীমা) +log_chalu(app); // request logging (লগ চালু)`} +
+ +
+ +

Sub-router Mounting (bebohar - ব্যবহার)

+
+{`dhoro userRoutes = router_banao(); +userRoutes.ana("/users", kaj(req, res) { json_uttor(res, {"users": []}); }); +userRoutes.pathano("/users", kaj(req, res) { json_uttor(res, {}, 201); }); + +dhoro app = router_banao(); +app.bebohar("/api", userRoutes); +// Now: GET /api/users, POST /api/users`} +
+ +
+ +

Full Production Example

+
+{`dhoro app = router_banao(); + +cors_chharpao(app); +log_chalu(app); +sankochon_chalu(app); +somoy_shima(app, 30); +akaar_shima(app, 1048576); +goti_shima(app, 100, 60); + +app.majhe(kaj(req, res, agorao) { + dekho(req["method"], req["path"]); + agorao(); +}); + +file_dao(app, "/public", "./static"); + +app.ana("/users/:id", kaj(req, res) { + dhoro id = req["params"]["id"]; + json_uttor(res, {"id": id}); +}); + +app.pathano("/users", kaj(req, res) { + dhoro user = req["json"]; + json_uttor(res, {"created": sotti}, 201); +}); + +app.ana("/search", kaj(req, res) { + dhoro q = req["query"]["q"]; + json_uttor(res, {"results": []}); +}); + +bhul_sambhalo(app, kaj(err, req, res) { + json_uttor(res, {"error": err["message"]}, 500); +}); + +server_chalu(3000, app);`} +
+ +
+

Related Topics