Skip to main content

Flask RESTX Extended

Tests status Code coverage Documentation status License Supported Python versions Join the chat at https://gitter.im/python-restx Code style: black

Flask-RESTX-Extended is a fork of Flask-RESTX.

This version fix reverse proxy swagger ui load error on Flask-RESTX.

Compatibility

Flask-RESTX-Extended requires Python 2.7 or 3.4+.

Installation

You can install Flask-RESTX-Extended with pip:

$ pip install flask-restx-extended

Quick start

With Flask-RESTX, you only import the api instance to route and document your endpoints.

from flask import Flask
from flask_restx import Api, Resource, fields

app = Flask(__name__)
app["SWAGGER_BASEURL"] = "/base"
api = Api(app, version='1.0', title='TodoMVC API',
    description='A simple TodoMVC API',
)

ns = api.namespace('todos', description='TODO operations')

todo = api.model('Todo', {
    'id': fields.Integer(readonly=True, description='The task unique identifier'),
    'task': fields.String(required=True, description='The task details')
})


class TodoDAO(object):
    def __init__(self):
        self.counter = 0
        self.todos = []

    def get(self, id):
        for todo in self.todos:
            if todo['id'] == id:
                return todo
        api.abort(404, "Todo {} doesn't exist".format(id))

    def create(self, data):
        todo = data
        todo['id'] = self.counter = self.counter + 1
        self.todos.append(todo)
        return todo

    def update(self, id, data):
        todo = self.get(id)
        todo.update(data)
        return todo

    def delete(self, id):
        todo = self.get(id)
        self.todos.remove(todo)


DAO = TodoDAO()
DAO.create({'task': 'Build an API'})
DAO.create({'task': '?????'})
DAO.create({'task': 'profit!'})


@ns.route('/')
class TodoList(Resource):
    '''Shows a list of all todos, and lets you POST to add new tasks'''
    @ns.doc('list_todos')
    @ns.marshal_list_with(todo)
    def get(self):
        '''List all tasks'''
        return DAO.todos

    @ns.doc('create_todo')
    @ns.expect(todo)
    @ns.marshal_with(todo, code=201)
    def post(self):
        '''Create a new task'''
        return DAO.create(api.payload), 201


@ns.route('/<int:id>')
@ns.response(404, 'Todo not found')
@ns.param('id', 'The task identifier')
class Todo(Resource):
    '''Show a single todo item and lets you delete them'''
    @ns.doc('get_todo')
    @ns.marshal_with(todo)
    def get(self, id):
        '''Fetch a given resource'''
        return DAO.get(id)

    @ns.doc('delete_todo')
    @ns.response(204, 'Todo deleted')
    def delete(self, id):
        '''Delete a task given its identifier'''
        DAO.delete(id)
        return '', 204

    @ns.expect(todo)
    @ns.marshal_with(todo)
    def put(self, id):
        '''Update a task given its identifier'''
        return DAO.update(id, api.payload)


if __name__ == '__main__':
    app.run(debug=True)

Release files for flask-restx-extended 0.5.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flask-restx-extended 0.5.2
File Size Uploaded
flask-restx-extended-0.5.2.tar.gz 61.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for flask-restx-extended 0.5.2
File Interpreter ABI Platform
flask_restx_extended-0.5.2-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 129.3 kB

Release files / flask-restx-extended-0.5.2.tar.gz

Download URL flask-restx-extended-0.5.2.tar.gz
Size 61.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b2c7b0eac0f047c1ee3a45c3cbb65966c916e771d544e01ed9e18822e81249ce
BLAKE2b-256 checksum
How to use checksums
c045400785c0c5ea1db534a428cf7eafac6c484775aa2a040744dfbc60d2f9ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.7

Release files / flask_restx_extended-0.5.2-py2.py3-none-any.whl

Download URL flask_restx_extended-0.5.2-py2.py3-none-any.whl
Size 68.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
60f5ea20a3e862c50af3659a709b85dd0a3e64e2b2f59f987f0ddc861b048c67
BLAKE2b-256 checksum
How to use checksums
fd404463ea9e61e1e758116809f98cf32e5954affda152c3dc7b365e7beb3b45
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.7

Release history Release notifications | RSS feed

This release

0.5.2 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page