I've been building an HTTP server in VB6 and just added two features that make it feel a lot more like a modern web framework:
? Parameter Routes ({param})
Define dynamic URL segments just like Laravel, Express, or Flask:
Code:
' Register routes with parameters
Router.Add "/api/user/{id}", "UserController@Show", OnlyGet
Router.Add "/api/user/{userId}/post/{postId}", "PostController@Show", OnlyGet
Router.Add "/api/group/{groupId}/user/{userId}", "GroupCtrl@Detail", OnlyGet
Retrieve them in your controller via RouteParams:
Public Sub Show(ctx As cHttpServerContext)
Dim id As String
id = ctx.Request.RouteParams("id") ' e.g. "123"
ctx.Response.Json Array("userId" & id)
End Sub
Matching rules:
Fixed segments match exactly (case-insensitive)
- {name} matches any non-empty segment
- Segment count must match
- Exact routes are matched first (O(1) dict lookup), then parameter routes are tried
? PathInfoList — Quick Access to URL Segments
Every request now has a PathInfoList collection that splits the URL path into indexed, keyed segments:
Code:
' Request: GET /api/user/list?page=1
ctx.Request.PathInfoList(1) ' ? "api"
ctx.Request.PathInfoList(2) ' ? "user"
ctx.Request.PathInfoList(3) ' ? "list"
ctx.Request.PathInfoList.Count ' ? 3
' Check if a segment exists
If ctx.Request.PathInfoList.Exists("api") Then ...
' Iterate all segments
Dim i As Long
For i = 1 To ctx.Request.PathInfoList.Count
Debug.Print ctx.Request.PathInfoList(i)
Next i
Full RESTful Example
' Routes
Router.Reg "Product", New cProductController
Router.Add "/products", "Product@List", OnlyGet
Router.Add "/products/{id}", "Product@Detail", OnlyGet
Router.Add "/products/{id}/reviews", "Product@Reviews", OnlyGet
Router.Add "/products", "Product@Create", OnlyPost
Router.Add "/products/{id}", "Product@Update", OnlyPut
Router.Add "/products/{id}", "Product@Delete", OnlyDelete
' Controller
Public Sub Detail(ctx As cHttpServerContext)
Dim id As String
id = ctx.Request.RouteParams("id")
' ... fetch from DB ...
ctx.Response.Json product
End Sub
What's New in Code
File Change
cHttpServerRouteItem.cls NEW — Parses {param} patterns, matches paths, extracts params
cHttpServerRouter.cls Updated matching: exact match first, then parameter route traversal
cHttpServerRequest.cls Added RouteParams (Dictionary) and PathInfoList (cCollection)
100% backward compatible — existing exact-match routes work exactly as before.
Open source at: https://github.com/woeoio/vbman
Docunmet: https://doc.vb6.pro/en/vbman/httpserver/overview.html