Skip to main content

Flask integration for route-bridge - define routes once, call them from the frontend as typed functions

Project description

flask-route-bridge

Flask integration for route-bridge.

Define your Flask routes with metadata, emit a shared manifest, and generate a typed TypeScript frontend client automatically.

Install

pip install flask-route-bridge

Quick start

from flask import Flask
from flask_route_bridge import RouteBridge

app = Flask(__name__)
rb = RouteBridge(app, manifest_path="./route-bridge.manifest.json", url_prefix="/api")

@rb.route(
    name="createUser",
    method="POST",
    path="/users",
    body={"name": "string", "email": "string"},
    response={"id": "string", "name": "string"},
)
def create_user(body, query, params, request):
    return {"id": "abc", "name": body["name"]}

if __name__ == "__main__":
    rb.write_manifest()   # writes route-bridge.manifest.json
    app.run(port=3001)

Then generate the TypeScript client:

npx route-bridge generate \
  --manifest ./route-bridge.manifest.json \
  --output ../frontend/src/generated

API

RouteBridge(app?, *, manifest_path, logging, url_prefix)

Param Type Default Description
app Flask None Flask app (or pass later via init_app)
manifest_path str ./route-bridge.manifest.json Where to write the manifest
logging bool True in debug mode Enable request logging
url_prefix str "" URL prefix for all routes

@rb.route(name, method, path, body?, query?, params?, response?, description?)

Decorator that registers a Flask route and records its metadata.

Handler signature: fn(body, query, params, request) -> dict

rb.write_manifest()

Writes the manifest to manifest_path. Call at startup.

rb.init_app(app)

Attach to a Flask app after construction (application factory pattern).

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flask_route_bridge-0.1.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flask_route_bridge-0.1.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file flask_route_bridge-0.1.0.tar.gz.

File metadata

  • Download URL: flask_route_bridge-0.1.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for flask_route_bridge-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6361f3e844c25176e50444efaf61aea8a9eadd862ec2ef08e2e60b834cd70405
MD5 be1ff1dfa48d8be3eefc4f251258ca5c
BLAKE2b-256 31cbad92fb3e999dbaf7c2136b903860df57122a3168ea3a0a119b7eb2f36b9c

See more details on using hashes here.

File details

Details for the file flask_route_bridge-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for flask_route_bridge-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ff4052ebb24f902dbeb9880131cc9db995f997896b5207018aea19959b47182b
MD5 92dab43fd7cf3029fc3291cc20f53b29
BLAKE2b-256 524b4109db589f57721129f856f03dd14ffc5b1bd4270e2fd2e0df6015a7b601

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page