Skip to main content

Falcon filtering helper

Project description

https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square https://travis-ci.org/Darkheir/falcon-filtering-hook.svg?branch=master https://codecov.io/gh/Darkheir/falcon-filtering-hook/branch/master/graph/badge.svg https://api.codacy.com/project/badge/Grade/151e8f92301d431eb6144cf7915ef897 Updates

A small falcon hook to parse filtering elements from the request.

Usage

The easiest way to use this hook is the following:

class Resource:
    filtering_fields = ("foo", "bar")  # List of fields allowed for filtering

    @falcon.before(FilteringHook())
    def on_get(self, req, resp, user):
        # Here req['context']['filters'] is set

The Hook will look in the query parameters for parameters looking like filter[key]=value.

It will create a filters dict into the request context accessible at req.context['filters']. Inside this dict the key will be the one extracted from between the brackets. i.e. key in the example above.

Configuration options

Allowing fields to be filtered

For security reasons, the fields allowed for filtering must be specified in the filtering_fields attribute of the resource.

All the fields not defined in it will be discarded by the hook.

Hook configuration

One parameter can be passed to the hook:

  • filtering_key : The base name of the key used for the filters. Default: filter.

Example:

@falcon.before(PaginationFromRequestHook(
    filtering_key='custom_filter',
))
def on_get(self, req, resp, user):
    # Get request

Project details


Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
falcon_filtering-0.2.0-py3-none-any.whl (4.1 kB) Copy SHA256 hash SHA256 Wheel py3
falcon_filtering-0.2.0.tar.gz (3.2 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page