Fixed Reverse Proxy Swagger Error of Restx
Project description
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)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file flask-restx-extended-0.5.2.tar.gz
.
File metadata
- Download URL: flask-restx-extended-0.5.2.tar.gz
- Upload date:
- Size: 61.3 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2c7b0eac0f047c1ee3a45c3cbb65966c916e771d544e01ed9e18822e81249ce |
|
MD5 | cd593e17ea881ebe145f64b0815b88f4 |
|
BLAKE2b-256 | c045400785c0c5ea1db534a428cf7eafac6c484775aa2a040744dfbc60d2f9ab |
File details
Details for the file flask_restx_extended-0.5.2-py2.py3-none-any.whl
.
File metadata
- Download URL: flask_restx_extended-0.5.2-py2.py3-none-any.whl
- Upload date:
- Size: 68.0 kB
- Tags: Python 2, Python 3
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60f5ea20a3e862c50af3659a709b85dd0a3e64e2b2f59f987f0ddc861b048c67 |
|
MD5 | 36719531e6a66402ade702e4b9a1f7aa |
|
BLAKE2b-256 | fd404463ea9e61e1e758116809f98cf32e5954affda152c3dc7b365e7beb3b45 |