Questions tagged [flask-restx]

Flask-RESTX is an extension for Flask that adds support for quickly building REST APIs in Python. Flask-RESTX is a community-driven fork of Flask-RESTPlus, hence users can also make use of [flask-restplus] tag in addition to [flask-restx] to search for relevant issues and questions.

Flask-RESTX is an extension for Flask that adds support for quickly building REST APIs.

Flask-RESTX encourages best practices with minimal setup. If you are familiar with Flask, Flask-RESTX should be easy to pick up.

It provides a coherent collection of decorators and tools to describe your API and expose its documentation properly using Swagger.

Flask-RESTX is a community driven fork of Flask-RESTPlus


A Minimal API

A minimal Flask-RESTX API looks like this:

from flask import Flask
from flask_restx import Resource, Api

app = Flask(__name__)
api = Api(app)

@api.route('/hello')
class HelloWorld(Resource):
    def get(self):
        return {'hello': 'world'}

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

Compatibility

Flask-RESTX requires Python 2.7 or 3.4+.

Documentation

The documentation is hosted on Read the Docs

108 questions
0
votes
1 answer

Using Flask-JWT-Extended with Flask-restx

I'm building an API using Flask-restx, I'm using a token system for authentication, I'm using Flask-JWT-Extended, in my case I managed to get the token, but I'm having trouble putting it in views, I'm using a decorator @jwt_required decorator on…
0
votes
1 answer

flask-restx how to convert a model to an example

I use flask-restx 0.5.1 to define my API. When describing payload parameter with @ns.expect(mymodel, description="my model parameter description") I get the following When I additionally use @ns.param('payload', description="This is my payload…
x y
  • 911
  • 9
  • 27
0
votes
2 answers

Deploy Flask API on Apache, with mod_wsgi

I've followed several tutorials at this point and know this has to be some minor issue. PLEASE help me find it! I have a Flask API, using Flask-Restx, ready to go and a remote Debian VPS with Apache. I'm not using a virtual environment. My project…
A_Wunder
  • 96
  • 1
  • 7
0
votes
1 answer

Flask-Restx fails to render Swagger doc when inputs.email is used

Whenever I try to define an argument in reqparse object, using the flask_restx.inputs.email type and decorate the method via api.expect; Flask-Restx fails to create the Swagger doc. Example code: @api.route("/route") class View(Resource): …
s3lcuk
  • 1
0
votes
1 answer

Flask restx api model not showing model data

I have a model as follows: class Menu(db.Model): itemId = db.Column(db.Integer,primary_key=True) name = db.Column(db.String(255),index=True) price = db.Column(db.Numeric) description = db.Column(db.String(255),index=True) image =…
Can
  • 1
  • 1
0
votes
1 answer

testdriven.io: Test-Driven Development with FastAPI and Docker: Get routes not working together

I'm following the testdriven.io course. I've found that by adding the GET All users route does not work as the request expects a userid. In the users.py file I have: def get(self): return User.query.all(), 200 and def get(self,…
jason
  • 64
  • 6
0
votes
1 answer

Api endpoints do not register in Flask-Restx

I've been following some tutorials(basic examples), trying to create a RESTful API with Flask-Restx. However, when I try to register endpoints with a more complex project structure(following this example), no API endpoints get registered. I defined…
0
votes
0 answers

flask-sqlalchemy join all matches from association table

I am doing a project in Flask, I have a difficulty with Flask-SQLAlchemy. class Films(db.Model): """Main film table""" __tablename__ = 'films' film_id = db.Column(db.Integer, primary_key=True) film_name = db.Column(db.Text,…
Dima
  • 3
  • 3
0
votes
1 answer

What is lifetime of Flask-RESTPlus Resource class?

Basically I need to know whether I can use @functools.cached_property in a Flask-RESTPlus Resource subclass to cache an expensive operation or collaborator construction that should not survive beyond a single request. I'm thinking there are two…
scanny
  • 26,423
  • 5
  • 54
  • 80
0
votes
1 answer

How to correct response format for flask rest api?

I'm developing a REST API with flask flask-restx. I want all my response will be formatted like this { "code": 200, "status": "success", "message": "OK", "data": { } } from flask import request from flask_restx import Resource from…
Shahrear Bin Amin
  • 1,075
  • 13
  • 31
0
votes
1 answer

Disable/Patch flask_of_oil OAuthFilter decorator for unittests

I have created a simple flask app that requires some end points to be called with a token bearer authentication. The opaque token is validated using the flask_of_oil OAuthFilter decorator with the proper client and secret combination. This works as…
T. Moser
  • 111
  • 1
  • 10
0
votes
1 answer

Regarding the problem of the route function according to the API object declaration location of Flask_restx

Flask restx is a library that develops api functions by dividing them into files in the flask framework and supports swaggerui. When serving api and web pages on one flask server, the api part can be divided into files and developed using…
0
votes
1 answer

Swagger documentation for API response with flask-restx

I'm reading the documentation for swagger documentation with flask-restx, and following the examples. I understand that in order to generate swagger docs for the parameters the API takes, I should do @api.doc(params={'id': 'An ID'}) However, I…
bjarkemoensted
  • 2,557
  • 3
  • 24
  • 37
0
votes
1 answer

Flask fields model empty list

How to make a model for an empty list only? I have one now that looks like this: config_model = api.model( 'update_config_fields', { 'some_key': fields.List(fields.String, required=True), } ) This appears in the Swagger…
JeffSpicoli
  • 101
  • 1
  • 8
0
votes
1 answer

How do I define a base endpoint for my Python Flask application with swagger?

I'm trying to build a simple Flask application with Swagger. So far, after a few tutorials this is what my main.py looks like: import logging import os import random from flask_restx import Api, Resource, fields from src import create_app app =…
Saturnian
  • 1,686
  • 6
  • 39
  • 65