Skip to content

FEAT: Adding --json output option in /cli/core .py on routes command #4417

@MauricioReisdoefer

Description

@MauricioReisdoefer

Summary

Feature Request: Add --json Option to routes Command

Description

Currently, the routes command outputs the list of application routes in a human-readable table format.
It would be useful to add a --json flag to allow users to export the routes in JSON format, making it easier to programmatically consume the route information.

Proposed Solution

  • Add a --json option to the routes CLI command.
  • When --json is provided, output the list of routes as a JSON array instead of the default table.
  • Ensure that the JSON output includes all relevant route details (e.g., path, methods, name, handler, etc.).
  • Update or add tests to validate JSON output.

Benefits

  • Programmatic access to route data for tooling or documentation generation.
  • Improves automation and integration with other tools.

Additional Context

This feature is especially useful for larger applications where manual inspection of routes is cumbersome, or when generating automated documentation.

Basic Example

Example Usage

$ litestar routes --json
[
  {
    "name": h.name,
    "path": h.paths,
    "handler": h.handler_name,
    "methods": sorted(h.http_methods),
    "async": inspect.iscoroutinefunction(unwrap_partial(h.fn))  
  },
]

Drawbacks and Impact

Drawbacks

Some drawbacks only occurs in particular cases.

  • Potential for sensitive information exposure
  • Performance impact
  • Maintenance overhead

Unresolved questions

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementThis is a new feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions