Results 1 to 4 of 4

Thread: VB6 HTTP Server — Now with Route Parameters & Path Segments

  1. #1

    Thread Starter
    Junior Member woeoio's Avatar
    Join Date
    Jan 2022
    Posts
    23

    VB6 HTTP Server — Now with Route Parameters & Path Segments

    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

  2. #2
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,672

    Re: VB6 HTTP Server — Now with Route Parameters & Path Segments

    Hello. Maybe you would like to post it in the Codebank.
    Or you could ask a moderator to move this thread there.

  3. #3

    Thread Starter
    Junior Member woeoio's Avatar
    Join Date
    Jan 2022
    Posts
    23

    Re: VB6 HTTP Server — Now with Route Parameters & Path Segments

    Quote Originally Posted by Eduardo- View Post
    Hello. Maybe you would like to post it in the Codebank.
    Or you could ask a moderator to move this thread there.
    Oh, okay. This is a very good note. Then I will take the time to sort out a more complete work introduction and post it to codebank. Thank you very much

  4. #4

    Thread Starter
    Junior Member woeoio's Avatar
    Join Date
    Jan 2022
    Posts
    23

    Re: VB6 HTTP Server — Now with Route Parameters & Path Segments

    Quote Originally Posted by Eduardo- View Post
    Hello. Maybe you would like to post it in the Codebank.
    Or you could ask a moderator to move this thread there.
    Oh, okay. This is a very good note. Then I will take the time to sort out a more complete work introduction and post it to codebank. Thank you very much

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width