当前位置: 首页>>代码示例>>Python>>正文


Python flask_restx.Resource方法代码示例

本文整理汇总了Python中flask_restx.Resource方法的典型用法代码示例。如果您正苦于以下问题:Python flask_restx.Resource方法的具体用法?Python flask_restx.Resource怎么用?Python flask_restx.Resource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在flask_restx的用法示例。


在下文中一共展示了flask_restx.Resource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_app

# 需要导入模块: import flask_restx [as 别名]
# 或者: from flask_restx import Resource [as 别名]
def create_app(env=None):
    from flask_restx import Api, Namespace, Resource

    app = Flask(__name__)
    api = Api(app)

    @app.route("/simple/make_a_widget", methods=["POST"])
    @accepts(dict(name="some_arg", type=str), schema=WidgetSchema)
    @responds(schema=WidgetSchema)
    def post():
        from flask import jsonify

        return request.parsed_obj

    @api.route("/restx/make_a_widget")
    class WidgetResource(Resource):
        @accepts(dict(name="some_arg", type=str), schema=WidgetSchema, api=api)
        @responds(schema=WidgetSchema, api=api)
        def post(self):
            from flask import jsonify

            return request.parsed_obj

    return app 
开发者ID:apryor6,项目名称:flask_accepts,代码行数:26,代码来源:marshmallow_example.py

示例2: create_app

# 需要导入模块: import flask_restx [as 别名]
# 或者: from flask_restx import Resource [as 别名]
def create_app(env=None):
    from flask_restx import Api, Namespace, Resource

    app = Flask(__name__)
    api = Api(app)

    @api.route("/restx/make_a_widget")
    class DoodadResource(Resource):
        @accepts(schema=DoodadSchema, api=api)
        @responds(schema=DoodadSchema, api=api)
        def post(self):
            from flask import jsonify

            return request.parsed_obj

    return app 
开发者ID:apryor6,项目名称:flask_accepts,代码行数:18,代码来源:dates_example.py

示例3: create_app

# 需要导入模块: import flask_restx [as 别名]
# 或者: from flask_restx import Resource [as 别名]
def create_app():
    app = Flask(__name__)
    api = Api(app)

    @api.route("/widget")
    class WidgetResource(Resource):
        @accepts("WidgetCreate", schema=WidgetSchema(only=["foo", "baz"]), api=api)
        @responds(schema=WidgetSchema, api=api)
        def post(self):
            # save data to a new record, and return ID
            return request.parsed_obj

        @accepts(dict(name="id", type=int), schema=WidgetSchema, api=api)
        @responds(schema=WidgetSchema(exclude=["created_at"]), api=api)
        def patch(self):
            return request.parsed_obj

    return app 
开发者ID:apryor6,项目名称:flask_accepts,代码行数:20,代码来源:schema_with_excluded_fields.py

示例4: create_app

# 需要导入模块: import flask_restx [as 别名]
# 或者: from flask_restx import Resource [as 别名]
def create_app(env=None):
    from flask_restx import Api, Namespace, Resource

    app = Flask(__name__)
    api = Api(app)

    @api.route("/restx/make_a_widget")
    class WidgetResource(Resource):
        @accepts(schema=WidgetSchema, api=api)
        @responds(schema=WidgetSchema, api=api)
        def post(self):
            from flask import jsonify

            return request.parsed_obj

    return app 
开发者ID:apryor6,项目名称:flask_accepts,代码行数:18,代码来源:marshmallow_validator_example.py

示例5: test_arguments_are_added_to_request_with_Resource_and_schema

# 需要导入模块: import flask_restx [as 别名]
# 或者: from flask_restx import Resource [as 别名]
def test_arguments_are_added_to_request_with_Resource_and_schema(app, client):  # noqa
    class TestSchema(Schema):
        _id = fields.Integer()
        name = fields.String()

    api = Api(app)

    @api.route("/test")
    class TestResource(Resource):
        @accepts(
            "Foo",
            dict(name="foo", type=int, help="An important foo"),
            schema=TestSchema,
            api=api,
        )
        def post(self):
            assert request.parsed_obj
            assert request.parsed_obj["_id"] == 42
            assert request.parsed_obj["name"] == "test name"
            return "success"

    with client as cl:
        resp = cl.post("/test?foo=3", json={"_id": 42, "name": "test name"})
        assert resp.status_code == 200 
开发者ID:apryor6,项目名称:flask_accepts,代码行数:26,代码来源:decorators_test.py

示例6: test_respond_schema_instance

# 需要导入模块: import flask_restx [as 别名]
# 或者: from flask_restx import Resource [as 别名]
def test_respond_schema_instance(app, client):  # noqa
    class TestSchema(Schema):
        _id = fields.Integer()
        name = fields.String()

    api = Api(app)

    @api.route("/test")
    class TestResource(Resource):
        @responds(schema=TestSchema(), api=api)
        def get(self):
            obj = {"_id": 42, "name": "Jon Snow"}
            return obj

    with client as cl:
        resp = cl.get("/test")
        obj = resp.json
        assert obj["_id"] == 42
        assert obj["name"] == "Jon Snow" 
开发者ID:apryor6,项目名称:flask_accepts,代码行数:21,代码来源:decorators_test.py

示例7: test_respond_schema_instance_respects_exclude

# 需要导入模块: import flask_restx [as 别名]
# 或者: from flask_restx import Resource [as 别名]
def test_respond_schema_instance_respects_exclude(app, client):  # noqa
    class TestSchema(Schema):
        _id = fields.Integer()
        name = fields.String()

    api = Api(app)

    @api.route("/test")
    class TestResource(Resource):
        @responds(schema=TestSchema(exclude=("_id",)), api=api)
        def get(self):
            obj = {"_id": 42, "name": "Jon Snow"}
            return obj

    with client as cl:
        resp = cl.get("/test")
        obj = resp.json
        assert "_id" not in obj
        assert obj["name"] == "Jon Snow" 
开发者ID:apryor6,项目名称:flask_accepts,代码行数:21,代码来源:decorators_test.py

示例8: test_respond_schema_respects_many

# 需要导入模块: import flask_restx [as 别名]
# 或者: from flask_restx import Resource [as 别名]
def test_respond_schema_respects_many(app, client):  # noqa
    class TestSchema(Schema):
        _id = fields.Integer()
        name = fields.String()

    api = Api(app)

    @api.route("/test")
    class TestResource(Resource):
        @responds(schema=TestSchema, many=True, api=api)
        def get(self):
            obj = [{"_id": 42, "name": "Jon Snow"}]
            return obj

    with client as cl:
        resp = cl.get("/test")
        obj = resp.json
        assert obj == [{"_id": 42, "name": "Jon Snow"}] 
开发者ID:apryor6,项目名称:flask_accepts,代码行数:20,代码来源:decorators_test.py

示例9: test_respond_schema_instance_respects_many

# 需要导入模块: import flask_restx [as 别名]
# 或者: from flask_restx import Resource [as 别名]
def test_respond_schema_instance_respects_many(app, client):  # noqa
    class TestSchema(Schema):
        _id = fields.Integer()
        name = fields.String()

    api = Api(app)

    @api.route("/test")
    class TestResource(Resource):
        @responds(schema=TestSchema(many=True), api=api)
        def get(self):
            obj = [{"_id": 42, "name": "Jon Snow"}]
            return obj

    with client as cl:
        resp = cl.get("/test")
        obj = resp.json
        assert obj == [{"_id": 42, "name": "Jon Snow"}] 
开发者ID:apryor6,项目名称:flask_accepts,代码行数:20,代码来源:decorators_test.py

示例10: test_responds_passes_raw_responses_through_untouched

# 需要导入模块: import flask_restx [as 别名]
# 或者: from flask_restx import Resource [as 别名]
def test_responds_passes_raw_responses_through_untouched(app, client):  # noqa
    class TestSchema(Schema):
        _id = fields.Integer()
        name = fields.String()

    api = Api(app)

    @api.route("/test")
    class TestResource(Resource):
        @responds(schema=TestSchema, api=api)
        def get(self):
            from flask import make_response, Response

            obj = {"_id": 42, "name": "Jon Snow"}
            return Response("A prebuild response that won't be serialised", 201)

    with client as cl:
        resp = cl.get("/test")
        assert resp.status_code == 201 
开发者ID:apryor6,项目名称:flask_accepts,代码行数:21,代码来源:decorators_test.py

示例11: test_responds_respects_status_code

# 需要导入模块: import flask_restx [as 别名]
# 或者: from flask_restx import Resource [as 别名]
def test_responds_respects_status_code(app, client):  # noqa
    class TestSchema(Schema):
        _id = fields.Integer()
        name = fields.String()

    api = Api(app)

    @api.route("/test")
    class TestResource(Resource):
        @responds(schema=TestSchema, api=api, status_code=999)
        def get(self):
            from flask import make_response, Response

            obj = {"_id": 42, "name": "Jon Snow"}
            return obj

    with client as cl:
        resp = cl.get("/test")
        assert resp.status_code == 999 
开发者ID:apryor6,项目名称:flask_accepts,代码行数:21,代码来源:decorators_test.py

示例12: test_responds_respects_envelope

# 需要导入模块: import flask_restx [as 别名]
# 或者: from flask_restx import Resource [as 别名]
def test_responds_respects_envelope(app, client):  # noqa
    class TestSchema(Schema):
        _id = fields.Integer()
        name = fields.String()

    api = Api(app)

    @api.route("/test")
    class TestResource(Resource):
        @responds(schema=TestSchema, api=api, envelope='test-data')
        def get(self):
            from flask import make_response, Response

            obj = {"_id": 42, "name": "Jon Snow"}
            return obj

    with client as cl:
        resp = cl.get("/test")
        assert resp.status_code == 200
        assert resp.json == {'test-data': {'_id': 42, 'name': 'Jon Snow'}} 
开发者ID:apryor6,项目名称:flask_accepts,代码行数:22,代码来源:decorators_test.py

示例13: test_partial_param_for_schema_loading

# 需要导入模块: import flask_restx [as 别名]
# 或者: from flask_restx import Resource [as 别名]
def test_partial_param_for_schema_loading(app, client):  # noqa
    class TestSchema(Schema):
        foo = fields.Str(required=True)
        bar = fields.Str(required=True)

    api = Api(app)

    @api.route("/test")
    class TestResource(Resource):
        @accepts(schema=TestSchema(), api=api, partial=True)
        def post(self):
            return "success"

    with client as cl:
        resp = cl.post("/test", json={"foo": 'foo', "bar": "bar"})
        assert resp.status_code == 200
        resp = cl.post("/test", json={"foo": 'foo'})
        assert resp.status_code == 200 
开发者ID:apryor6,项目名称:flask_accepts,代码行数:20,代码来源:decorators_test.py

示例14: setup_api

# 需要导入模块: import flask_restx [as 别名]
# 或者: from flask_restx import Resource [as 别名]
def setup_api(app):
    api = Api()
    api.init_app(app)

    @api.route('/test')
    class ExampleEndpoint(Resource):
        def get(self):
            return {'hello': 'world'} 
开发者ID:rycus86,项目名称:prometheus_flask_exporter,代码行数:10,代码来源:server.py

示例15: create_app

# 需要导入模块: import flask_restx [as 别名]
# 或者: from flask_restx import Resource [as 别名]
def create_app():
    app = Flask(__name__)
    api = Api(app)

    @api.route("/widget")
    class WidgetResource(Resource):
        @accepts(schema=WidgetSchema, api=api)
        @responds(schema=WidgetSchema, api=api)
        def post(self):
            # save data to a new record, and return ID
            return request.parsed_obj

    return app 
开发者ID:apryor6,项目名称:flask_accepts,代码行数:15,代码来源:load_dump_only.py


注:本文中的flask_restx.Resource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。