flasgger
is doing could be an interesting entry point. but it's going to take code change in flask-restx
@Gidgidonihah : Reading the code, the intent is that errorhandlers get checked for the restx.API and it's children (restx.API.namespace). It wouldn't make sense, to me, for the framework to go up the chain as well.
So self + children
vs. self + parents + children
. self + children
makes sense to me for checking handlers. But I may be misinterpreting the question?
@Abdur-rahmaanJ If you don't mind me asking, is this an on-prem or cloud hosted? And is it possible to add authentication at other layers? It depends a lot on your setup, but something like using JWT with NGinx, or x509 based auth at Apache Webserver are other possibilities. But there's a lot of nuance there. I do think we need to figure out a better way of handling the pre-generated doc endpoint, and I think what
flasgger
is doing could be an interesting entry point. but it's going to take code change inflask-restx
Cloud-hosted, server-based auth is a great option also but see the above
flask
and werkzeug
both released 2.0.0. unfortunately, there are a few breaking changes we'll need to work through. You can pin flask and werkzeug yourself, but we're also pinning flask-restx for the moment till some upstream things fix, and we can make sure we've got any breaking changes accounted for
werkzeug
and flask
with the flask-restx
.
Hey ,
I replied to the issue https://github.com/python-restx/flask-restx/issues/314#issuecomment-884753325
I think It can help a lot to resolve it
@E-Kalla thanks for really digging into the issue. I'd need to read a bit more to understand everything happening.
If you have an approach in mind, could you clearly state it in the issue? If it's to remove @cached_property
i'm not sure the entire range of effects there, in particular with regards to benchmarking
Hi, hope everyone is having a great Monday. I am currently setting up a POST method redirection using flask.redirect
. For some reason, the redirection does not work and I was not able to get any useful logging even when I set FLASK_ENV=development
. Here is the log I got:
127.0.0.1 - - [16/Aug/2021 16:49:57] "POST /runs HTTP/1.1" 200 -
[I 210816 16:49:57 _internal:122] 127.0.0.1 - - [16/Aug/2021 16:49:57] "POST /runs HTTP/1.1" 200 -
It seems this endpoint never got redirected.
Anyone has any insight on debugging this issue ?
Unfortunately, I am not able to provide any code here because the redirection works well when I tried to set up some dummy code, but it did not work with a big project that I am currently working on.
here is the log I got for dummy code that I set up:
127.0.0.1 - - [16/Aug/2021 17:04:51] "POST /todos2/1 HTTP/1.1" 307 -
127.0.0.1 - - [16/Aug/2021 17:04:51] "POST /todos/ HTTP/1.1" 200 -
From this log, the endpoint actually got redirected.
marshal_with
which seems changed returned redirection:import flask
from flask import Flask
from flask_restx import Model, Resource, fields, Namespace, abort, Api
from werkzeug.middleware.proxy_fix import ProxyFix
app = Flask(__name__)
app.wsgi_app = ProxyFix(app.wsgi_app)
api = Api(app, version='1.0', title='TodoMVC API',
description='A simple TodoMVC API',
)
ns = Namespace('todos', description='TODO operations')
ns2 = Namespace('todos2', description='TODO operations')
todo = Model('todo', {
'id': fields.Integer(required=True, description='The task unique identifier'),
'task': fields.String(required=True, description='The task details'),
'description': fields.String(required=True, description='Put some description here')
})
response = Model('response', {
'id': fields.Integer,
'task': fields.String
})
ns.models[todo.name] = todo
ns.models[response.name] = response
todo2 = Model('todo2', {
'task': fields.String(required=True, description='The task details'),
'todo_description': fields.String(required=True, description='Put some description here')
})
response2 = Model('response2', {
'id': fields.Integer,
'task': fields.String
})
ns2.models[todo2.name] = todo2
ns2.models[response2.name] = response
api.add_namespace(ns)
api.add_namespace(ns2)
@ns2.route('/<int:id>')
@ns2.response(404, 'Todo not found')
class Todo(Resource):
'''Show a single todo item and lets you delete them'''
@ns2.doc('get_todo')
def get(self, id):
'''Fetch a given resource'''
return "get todo 2"
@ns2.expect(todo2)
@ns2.marshal_with(response)
def post(self, id):
'''Update a task given its identifier'''
if id == 1:
redirection = flask.redirect(flask.url_for('todos_todo_list', _method='POST'), code=307)
return redirection
return {"id": "dummy id", "task": "some dummy task here"}
@ns.route('/')
class TodoList(Resource):
'''Shows a list of all todos, and lets you POST to add new tasks'''
@ns.doc('list_todos')
def get(self):
'''List all tasks'''
return "get todo list"
@ns.doc('create_todo')
@ns2.expect(todo)
@ns.marshal_with(response)
def post(self):
'''Create a new task'''
payload = ns.payload
return {"id": payload.get("id"), "task": payload.get("task")}
if __name__ == '__main__':
app.run(debug=True)
so the requirement is:
Given an endpoint with a variable (var == $CONDITION), have a redirect only for $CONDITION, otherwise, return properly
My gut would say, if you want a single endpoint, split by condition, to do 2 redirects. One for $CONDITION, one for everything else. and the resultant endpoints handling the marshalling. Because, in the end, if their responses are going to be different, they should probably be considered separate endpoints
Considering you're changing core functionality based upon a condition, i'd say keeping the original endpoint with 2 redirects, split by condition. then if you want to deprecate the v1 style endpoint later, you can
the other option is to split v1 and v2 endpoints, and just tell folks to use v2 for the new setup. Versioning and moving some endpoints is normal, and versioning is supported in flask-restx. you can provide version=
to the API generator.