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
1
vote
0 answers

How to model and marshal JSON list object with flask-restx marshalling

I have a Flask REST API that expects a list of dictionary values (represents a batch) in the POST request, which is valid JSON, and I would like to define the resource fields with flask-restx, but am uncertain how to go about it, as there is no key…
mgross
  • 550
  • 1
  • 7
  • 24
1
vote
1 answer

marshall with in restx for dictionary

I have a dictionary like below { "a": 2, "b": 1, "dd": { "xx": { "name": "Xx XxRay", "guid": "967436db-3f7b-40c3-94cb-45c7ac5a1787" }, "yy": { "name": "Yy YyZee", …
s_mj
  • 530
  • 11
  • 28
1
vote
1 answer

Adding a place for JWT Bearer Token to Swagger Documentation in Restx

I'm using the below structure authorizations = { 'apikey': { 'type': 'apiKey', 'in': 'header', 'name': 'X-API-KEY' } } api = Api(app, authorizations=authorizations) But in the swagger ui, i'm giving my token…
ilanm
  • 53
  • 6
1
vote
3 answers

Flask-Restx not converting enum field type to JSON

I need help with Enum field type as it is not accepted by Swagger and I am getting error message **TypeError: Object or Type eGameLevel is not JSON serializable**. Below is the complete set of code for table. Complete set of code with DB table and…
Shazia Nusrat
  • 174
  • 1
  • 10
  • 36
1
vote
1 answer

flask-restx how to create parser from model

I am using flask-restx for documenting and formatting my api I have a app, including a directory, holding json schemas in the following format: http://json-schema.org/draft-07/schema# (in my app they are saved as json file, in the below example I…
dina
  • 4,039
  • 6
  • 39
  • 67
1
vote
1 answer

flask restx - pytest in not working with error handler

I am building API using Flask Restx. I had written a generic exception handler which will throw an error message and code in Json format. @app.errorhandler(APIError) def handle_invalid_usage(error): logger.opt(exception=True).error(error) …
Arul
  • 143
  • 3
  • 12
1
vote
2 answers

Python/Flask: Return Message and Status Code to calling function?

I have a Flask App (build on top of the Flask Restx Resource class) and I've created a couple of try/except statements to validate the input of my app. To make the code of the app more readable, I'd like to encapsulate these checks in a seperate…
stats-hb
  • 958
  • 13
  • 31
1
vote
1 answer

Flask-Restx: Set default route from Swagger?

I have some database services that take a bit of time to run before my swagger interface is loaded. So, I want to load an HTML page with the information & then redirect it to the swagger documentation. How can I add a default route that I can load…
nithishr
  • 596
  • 1
  • 7
  • 17
1
vote
1 answer

General REST API: Insert Parent and Child at one request

I'm building a REST API with more or less complex resources. So let's say, i have the following Database Structure behind the Scenes. ParentBase: id|name ChildBase: id|name|parentId So, obviously column "parentId" of childBase is a foreignKey to…
Jakob
  • 113
  • 1
  • 10
1
vote
0 answers

Swagger (using flask-restx/plus) optional list/nested JSON

I need the API to accept: { 'field1' : 10, 'children' : [ 'c1', 'c2' ] } and also { 'field1' : 10, } i.e., when there are no children the field can be skipped. I tried defining the model: 'field1' : fields.Integer(example=42), …
mibm
  • 1,328
  • 2
  • 13
  • 23
1
vote
1 answer

How to specify a generic dictionary in payload of flask-restplus/flask-restx?

I have an API which receives a JSON looking like this { "some_key" : [ "v1", "v2" ] "another_key" : [ a1, a2, a3, a4 ] ... } So I wanted to define something along these lines dict_model = api.model('ArbitraryDict', { fields.String :…
mibm
  • 1,328
  • 2
  • 13
  • 23
1
vote
1 answer

Dropdown menu in Swagger with Flask (restx)

I am building my first API with the flask-restx lib. I use it to generate a Swagger documentation of my API with annotations. I currently have some fields for a post method but they all accept input as strings by default and you have to type their…
Ghostwriter
  • 2,461
  • 2
  • 16
  • 18
1
vote
2 answers

How to return a nested json response in Flask-Restx

I am trying to make an API with Flask-RestX that can show a response like this, { "id": 1, "msg": "How are things", "score": 345, "additional": { "goal": 56, "title": "ASking how" } } when data is like this (In my case, I do not…
realsdx
  • 28
  • 2
  • 7
1
vote
1 answer

How to use data obtained from DB as values in add_argument() when the Flask app starts?

I have the following project structure for a Flask app using flask-restx . ├── app │   ├── extensions.py │   ├── __init__.py │   └── pv_dimensioning │   ├── controller.py │   ├── __init__.py │   ├── models │   │   ├── dto.py │   …
some_programmer
  • 3,268
  • 4
  • 24
  • 59
1
vote
0 answers

Swagger is not working in server in flask-restx

I've deployed my flask-backend server with Nginx. I can see my swagger documentation locally going 127.0.0.1:5000 also going to my server IP address and port number server_ip:5000. Can I see my API documentation just going my server domain name?…
Shahrear Bin Amin
  • 1,075
  • 13
  • 31