New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bare path of '/' #247
Comments
@Climbgunks Here is the workaround: #!/usr/bin/python
from flask import Flask
from flask_restplus import Resource, Api as BaseApi
class Api(BaseApi):
def _register_doc(self, app_or_blueprint):
# HINT: This is just a copy of the original implementation with the last line commented out.
if self._add_specs and self._doc:
# Register documentation before root if enabled
app_or_blueprint.add_url_rule(self._doc, 'doc', self.render_doc)
#app_or_blueprint.add_url_rule(self._doc, 'root', self.render_root)
@property
def base_path(self):
return ''
app = Flask(__name__)
api = Api(app, doc='/swagger/')
ns = api.namespace('Test', description='Test operations', path='/')
@ns.route('/hello', '/', '/world')
@ns.doc()
class Hello(Resource):
def get(self):
return { 'hello': 'World' }
if __name__ == '__main__':
app.run(debug=True) flask-restplus implements def _register_doc(self, app_or_blueprint):
if self._add_specs and self._doc:
# Register documentation before root if enabled
app_or_blueprint.add_url_rule(self._doc, 'doc', self.render_doc)
app_or_blueprint.add_url_rule(self._doc, 'root', self.render_root) and here is the def render_root(self):
self.abort(404) Thus, I don't know how to override this handler other than subclassing the Api. |
Thanks..that workaround works. Btw, the current code uses the line: it does set the 'root' for base_path, not sure of the side effect of not setting it... |
Flask-restplus just needs a |
This is not a good user experience. Is there a future plan to improve this? |
I faced an issue similar to described here. Instead of request processing for route Request:
Response:
I use namespaced api structure: #! venv/bin/python
# -*- coding: utf-8 -*-
from flask_restplus import Api
from .Projects import api as projects
from .Dictionaries import api as dicts
# ... more of them ....
api = Api(
title='my api',
version='1.0'
)
api.add_namespace(projects)
api.add_namespace(dicts)
# ... more of them .... Projects.py #! venv/bin/python
# -*- coding: utf-8 -*-
from flask import request, json
from flask_restplus import Namespace, Resource, fields, abort
from db import DB
import logging
api = Namespace('projects', description='Projects related operations')
# ...
@api.route('/') # <----- This one gives 301
class ProjectList(Resource):
def get(self):
pass
# ... Dictionaries.py #! venv/bin/python
# -*- coding: utf-8 -*-
from flask_restplus import Namespace, Resource, abort
import logging
api = Namespace('dicts', description='Dictionaries related operations')
# ...
@api.route('/grouped') # <----- This one works as expected for url '/api/dicts/grouped'
class DictionaryGroup(Resource):
def get(self):
pass |
@frol I use path prefix E.g. this piece from previous version works as expected on #!venv/bin/python
# -*- coding: utf-8 -*-
from flask import Flask, jsonify, make_response, request
# ...
@app.route('/projects', methods=['GET'])
def get_projects():
pass
# ... |
@frol I found an answer. Werkzeug makes redirect trying to append slash at the end. # ...
api = Namespace('projects')
@api.route('/')
# ... route becomes |
The problem is especially nasty when you try to DELETE |
@dmig i'm facing the same issue, so what is exactly the solution to this? |
Use all urls with |
Don't know if there is still someone checking this issue, but I found a simple solution.
|
I got the same problem with
|
It seems that redirecting to a URL ends with '/' is Werkzeug's behaviour. Take a look at this https://stackoverflow.com/questions/21050320/flask-301-response . It not about restplus. |
I'm probably missing something obvious, but I can't seem to set a path of '/'
A simple test program that attempts to use both namespaces and swagger:
/hello and /world work as expected.... / throws a 404 whether through the swagger UI (http://localhost:5000/swagger) or through curl/wget
Assuming this isn't a bug in flask-restplus, how do I set an endpoint for '/'
The text was updated successfully, but these errors were encountered: