當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。