Skip to content

bug: server module missing HttpRequest type registration + undocumented functions #1585

@SchoolyB

Description

@SchoolyB

Summary

The server module's request type is documented in STANDARD.md as Request but is never registered in the typechecker. Users cannot write handler or middleware functions that accept request parameters. Additionally, server.cors() and server.use() (wired in #1580) are undocumented, and the request type should be renamed to HttpRequest for consistency with HttpResponse.

Problems

1. Request type not registered

STANDARD.md shows this handler pattern:

do home(req Request) -> HttpResponse {
    return server.text(200, "Welcome!")
}

But Request is never registered via register_struct() in the typechecker. HttpResponse is registered (with fields status, body, headers), but the request type is missing entirely. Any user code referencing Request as a type will fail — meaning path params, query strings, headers, and body are all inaccessible from handlers.

This also blocks server.use() — middleware functions need to accept request/response parameters, but without the request type registered that's not possible.

2. Naming inconsistency

The response type is HttpResponse but the request type is documented as Request. These should be a uniform pair: HttpRequest and HttpResponse.

3. Undocumented functions

server.cors() and server.use() were wired in #1580 but are not listed in the STANDARD.md server module routing table.

Fix

  1. Register HttpRequest as a struct in the typechecker with the following fields:

    Field Type
    method string
    path string
    body string
    query map[string:string]
    headers map[string:string]
    params map[string:string]
  2. Rename Request to HttpRequest in STANDARD.md docs, code examples, and handler signatures

  3. Add server.cors() and server.use() to the STANDARD.md routing table:

    • cors(router Router, origin string) — Enable CORS with the given origin
    • use(router Router, ()middleware) — Register a middleware function
  4. Update handler/middleware function signatures in codegen and typechecker to reference HttpRequest consistently

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdocumentationImprovements or additions to documentationstdlibGeneral standard library issuestypecheckerRelated to type checking and validation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions