How to use the falcon.App 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_redirects.py View on Github external
def client():
    app = falcon.App()

    resource = RedirectingResource()
    app.add_route('/', resource)

    return testing.TestClient(app)
github falconry / falcon / tests / test_request_media.py View on Github external
def create_client(handlers=None):
    res = testing.SimpleTestResource()

    app = falcon.App()
    app.add_route('/', res)

    if handlers:
        app.req_options.media_handlers.update(handlers)

    client = testing.TestClient(app)
    client.resource = res

    return client
github falconry / falcon / tests / test_httpstatus.py View on Github external
def test_raise_status_survives_after_hooks(self):
        """ Make sure after hook doesn't overwrite our status """
        app = falcon.App()
        app.add_route('/status', TestStatusResource())
        client = testing.TestClient(app)

        response = client.simulate_request(path='/status', method='DELETE')
        assert response.status == falcon.HTTP_200
        assert response.headers['x-failed'] == 'False'
        assert response.text == 'Pass'
github falconry / falcon / tests / test_wsgiref_inputwrapper_with_size.py View on Github external
def test_resources_can_read_request_stream_during_tests(self):
        """Make sure we can perform a simple request during testing.

        Originally, testing would fail after performing a request because no
        size was specified when calling `wsgiref.validate.InputWrapper.read()`
        via `req.stream.read()`"""
        app = falcon.App()
        type_route = '/type'
        app.add_route(type_route, TypeResource())
        client = testing.TestClient(app)

        result = client.simulate_post(path=type_route, body='hello')

        assert result.status == falcon.HTTP_200
        assert result.json == {'data': 'hello'}
github falconry / falcon / tests / test_utils.py View on Github external
def test_simulate_hostname(self):
        app = falcon.App()
        resource = testing.SimpleTestResource()
        app.add_route('/', resource)

        client = testing.TestClient(app)
        client.simulate_get('/', protocol='https',
                            host='falcon.readthedocs.io')
        assert resource.captured_req.uri == 'https://falcon.readthedocs.io/'
github falconry / falcon / tests / test_wsgi_errors.py View on Github external
def client():
    app = falcon.App()

    tehlogger = LoggerResource()
    app.add_route('/logger', tehlogger)
    return testing.TestClient(app)
github falconry / falcon / tests / test_utils.py View on Github external
def test_path_must_start_with_slash(self):
        app = falcon.App()
        app.add_route('/', testing.SimpleTestResource())
        client = testing.TestClient(app)
        with pytest.raises(ValueError):
            client.simulate_get('foo')
github falconry / falcon / tests / test_response_media.py View on Github external
def create_client(handlers=None):
    res = testing.SimpleTestResource()

    app = falcon.App()
    app.add_route('/', res)

    if handlers:
        app.resp_options.media_handlers.update(handlers)

    client = testing.TestClient(app)
    client.resource = res

    return client
github falconry / falcon / tests / test_sinks.py View on Github external
def client():
    app = falcon.App()
    return testing.TestClient(app)
github falconry / falcon / examples / things_advanced.py View on Github external
def on_post(self, req, resp, user_id):
        try:
            doc = req.context.doc
        except AttributeError:
            raise falcon.HTTPBadRequest(
                'Missing thing',
                'A thing must be submitted in the request body.')

        proper_thing = self.db.add_thing(doc)

        resp.status = falcon.HTTP_201
        resp.location = '/%s/things/%s' % (user_id, proper_thing['id'])


# Configure your WSGI server to load "things.app" (app is a WSGI callable)
app = falcon.App(middleware=[
    AuthMiddleware(),
    RequireJSON(),
    JSONTranslator(),
])

db = StorageEngine()
things = ThingsResource(db)
app.add_route('/{user_id}/things', things)

# If a responder ever raised an instance of StorageError, pass control to
# the given handler.
app.add_error_handler(StorageError, StorageError.handle)

# Proxy some things to another service; this example shows how you might
# send parts of an API off to a legacy system that hasn't been upgraded
# yet, or perhaps is a single cluster that all data centers have to share.