How to use the falcon.before function in falcon

To help you get started, we’ve selected a few falcon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github falconry / falcon / tests / test_query_params.py View on Github external
    @falcon.before(testing.set_resp_defaults)
    def on_head(self, req, resp, **kwargs):
        pass
github falconry / falcon / tests / test_before_hooks.py View on Github external
# Test passing a single extra arg
        super(TestFieldResourceChild, self).on_get(req, resp, id)


class TestFieldResourceChildToo(TestFieldResource):

    def on_get(self, req, resp, id):
        # Test passing a single kwarg, but no extra args
        super(TestFieldResourceChildToo, self).on_get(req, resp, id=id)


@falcon.before(bunnies)
@falcon.before(frogs)
@falcon.before(Fish())
@falcon.before(bunnies_in_the_head)
@falcon.before(frogs_in_the_head)
class ZooResource:

    def on_get(self, req, resp, bunnies, frogs, fish):
        self.bunnies = bunnies
        self.frogs = frogs
        self.fish = fish


class ZooResourceChild(ZooResource):

    def on_get(self, req, resp):
        super(ZooResourceChild, self).on_get(
            req,
            resp,

            # Test passing a mixture of args and kwargs
github j19sch / building-an-api-testing-framework / api_app / src / books.py View on Github external
    @falcon.before(validate_uuid)
    @falcon.before(validate_token)
    def on_delete(self, req, resp, book_id):
        if [book for book in self.books if book['id'] == book_id]:
            self.books[:] = [book for book in self.books if book["id"] != book_id]
            resp.status = falcon.HTTP_200
        else:
            resp.status = falcon.HTTP_NOT_FOUND
github falconry / falcon / tests / test_before_hooks.py View on Github external
    @falcon.before(_another_fish.hook)
    def on_delete(self, req, resp, fish, itemid):
        del self._items[itemid]
        resp.set_header('X-Fish-Trait', fish)
        resp.status = falcon.HTTP_NO_CONTENT
github falconry / falcon / tests / test_before_hooks.py View on Github external
    @falcon.before(header_hook)
    @falcon.before(_another_fish.hook)
    @falcon.before(header_hook)
    def on_delete_collection(self, req, resp, fish):
        if fish != 'wet':
            raise falcon.HTTPUnavailableForLegalReasons('fish must be wet')
        self._items = {}
        resp.status = falcon.HTTP_NO_CONTENT
github ironman5366 / W.I.L.L / will / API / v1.py View on Github external
    @falcon.before(hooks.client_is_official)
    @falcon.before(hooks.origin_client_auth)
    def on_get(self, req, resp, origin_client_id):
        """
        On a request from an official client, return data about the client.
        :param req:
        :param resp:
        :param origin_client_id:
        """
        # Match the client in the database
        session = db()
        client = session.query(Client).filter_by(client_id=origin_client_id).one_or_none()
        # Get the number of users that use it
        user_num = len(client.users)
        req.context["result"] = {"data":
                                     {"user_num": user_num,
                                      "id": "CLIENT_DATA_FETCHED",
github ProjectMeniscus / meniscus / meniscus / api / pairing / resources.py View on Github external
    @falcon.before(get_validator('pairing_configuration'))
    def on_post(self, req, resp, validated_body):
        body = validated_body['pairing_configuration']

        api_secret = body['api_secret']
        coordinator_uri = body['coordinator_uri']
        personality = body['personality']

        #start pairing on a separate process
        pairing_process = PairingProcess(
            api_secret, coordinator_uri, personality)
        pairing_process.run()

        resp.status = falcon.HTTP_200
github fiLLLip / plex-watched-sync / server / account.py View on Github external
    @falcon.before(Actions.validate_account_server_access)
    def on_get(self, req, resp, account_id):
        """Handles GET requests"""
        watched = Actions.get_watched(account_id)
        if watched is None:
            resp.status = falcon.HTTP_404
            return
        servers = Actions.get_servers(account_id)
        resp.status = falcon.HTTP_200  # This is the default status
        json_resp = {'account_id': account_id, 'watched': watched, 'servers': servers}
        resp.body = json.dumps(json_resp)
github Buzz2d0 / Hyuga / hyuga / api / v1 / users.py View on Github external
    @falcon.before(BaseValidate(postSchema).validate)
    def process_login(self, req, resp):
        req_data = req.context["data"]
        username = req_data["username"]
        password = req_data["password"]
        try:
            user = User.objects.filter(username=username).first()
        except redis.exceptions.ConnectionError:
            raise errors.DatabaseError(errors.ERR_DATABASE_CONNECTION)
        except Exception as e:
            _api_logger.info("UsersSelfOperation login ERROR: %s" % e)
            self.on_error(resp, errors.ERR_UNKNOWN)
        if not user:
            raise errors.UnauthorizedError()
        _api_logger.debug("password: %s, %s" % (password, user.password))
        if not PasswordHash.py_value(user.password).check_password(password):
            raise errors.UnauthorizedError()
github vfrico / kge-server / rest-service / endpoints / datasets.py View on Github external
    @falcon.before(read_triples_from_body)
    def on_post(self, req, resp, dataset_id, dataset_dto, triples_list):
        """Receives HTTP Request to add triples into the dataset

        This will expect an input on the body similar to this

        .. sourcecode:: json

            [
                {   "subject": "Q1492",
                    "predicate": "P17",
                    "object": "Q29" },
                {   "subject": "Q90",
                    "predicate": "P17",
                    "object": "Q142"},
                {   "subject": "Q2807",
                    "predicate": "P17",