Skip to main content

Opinionated FastAPI Extended Route

A small utility for FastAPI/Starlette Route and Request to address the following:

  • Request.url_for doesn't allow adding query parameters at the moment.
  • URL objects can't have multiple keys like /?key=value&key=anothervalue.

With the following changes:

  • Make Request.url_for to match path parameters and use unmatched params for query parameters.
  • Provide a custom Route which has a new Request type.
  • Allow URL object to add multiple keys in query params.
  • ...

Example:

from fastapi import FastAPI
from fastapi.responses import PlainTextResponse

from fastapi_extended_route import Request, Route

def index(request: Request) -> PlainTextResponse:
    url = request.url_for("index", key=value)
    # url == "http://testserver/?key=value"
    return PlainTextResponse(url)

app = FastAPI(
    routes=[Route("/", index, name="index")],
)

As you can see the only change is to use Route from the package and the new Request object will have a customized url_for method which handles both path parameters and query parameters.

If/when these options are available in Starlette/FastAPI, this is no longer needed.

Download files

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

Source Distribution

fastapi_extended_route-0.1.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

fastapi_extended_route-0.1.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastapi_extended_route-0.1.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for fastapi_extended_route-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0e73998e14696f5433f1061834a5ac8c04c9e88a87198746d78206c1f1332380
MD5 098b9e5aa193caf1045bb932e969d6af
BLAKE2b-256 ae6cfa29cecf644827a4628f4d8aca907697f28d3d023f997fa1e7c2e81f1466

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastapi_extended_route-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 02c8de0265aa045442ef204e11f77797bbddd63bf8b3e867696da971f279a818
MD5 927b728bef7cab44d0cf4f633fceb75c
BLAKE2b-256 429002a9f4d2f5ba8e88d73898b943857740cf9d3c3646ab6d18318edc796d70

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

0.0.0

2 files

Supported by

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