Code Monkey home page Code Monkey logo

fastapi-query-flatten's Introduction

QueryFlattenMiddleware for FastAPI

QueryFlattenMiddleware is a custom middleware for FastAPI applications that flattens query parameters separated by a specified delimiter. This is particularly useful for endpoints that need to handle multiple values for the same query parameter without using the standard array format.

Features

  • Customizable Delimiter: Easily configure the delimiter used for splitting query parameter values.
  • Seamless Integration: Works as middleware within any FastAPI application.
  • Efficient Query Handling: Simplifies the process of handling multiple query parameters by flattening them, making endpoint logic cleaner and more straightforward.

Requirements

  • Python 3.8.1+
  • FastAPI

Installation

To install QueryFlattenMiddleware, you can use pip:

pip install fastapi-query-flatten

Usage

To use QueryFlattenMiddleware in your FastAPI application, simply add it as middleware in your app instance. Specify the delimiter you want to use for splitting query parameter values. The default delimiter is a comma (,).

Example

from fastapi import FastAPI
from fastapi_query_flatten import QueryFlattenMiddleware

app = FastAPI()

# Add QueryFlattenMiddleware with a custom delimiter
app.add_middleware(QueryFlattenMiddleware, delimiter=",")

With the middleware in place, a request to /items/?filter=value1,value2,value3 will be processed as if it were /items/?filter=value1&filter=value2&filter=value3, allowing the filter query parameter to be easily handled as multiple values.

Contributing

Contributions are welcome! If you have a feature request, bug report, or a pull request, please open an issue or submit a PR on the project's repository.

License

This project is licensed under the MIT License - see the LICENSE file for details.

fastapi-query-flatten's People

Contributors

davidlin2k avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.