Questions tagged [flask-restful]

Flask-RESTful provides an extension to Flask for building REST APIs. Flask-RESTful was initially developed as an internal project at Twilio, built to power their public and internal APIs.

Project repo is maintain on Github currently.
The latest document is here
Its pypi info can be find here

1619 questions
8
votes
2 answers

json serialisation of dates on flask restful

I have the following resource: class Image(Resource): def get(self, db_name, col_name, image_id): col = mongo_client[db_name][col_name] image = col.find_one({'_id':ObjectId(image_id)}) try: image['_id'] =…
elelias
  • 4,552
  • 5
  • 30
  • 45
8
votes
1 answer

How to configure Sphinx auto flask to document flask-restful API?

I have a flask app that I want to use Sphinx's autoflask directive to document a flask-restful API. https://pythonhosted.org/sphinxcontrib-httpdomain/#module-sphinxcontrib.autohttp.flask I have installed the module via pip and run sphinx-quickstart,…
David Watson
  • 3,394
  • 2
  • 36
  • 51
8
votes
3 answers

Flask-RESTful: Using GET to download a file with REST

I am trying to write a file sharing application that exposes a REST interface. The library I am using, Flask-RESTful only supports returning JSON by default. Obviously attempting to serve binary data over JSON is not a good idea at all. What is the…
Ayrx
  • 2,092
  • 5
  • 26
  • 34
7
votes
8 answers

Flask-Restful Error: request Content-Type was not 'application/json'."}

I was following this tutorial and it was going pretty well. He then introduced reqparse and I followed along. I tried to test my code and I get this error {'message': "Did not attempt to load JSON data because the request Content-Type was not…
jadside
  • 135
  • 1
  • 1
  • 5
7
votes
1 answer

How to read a bearer token from postman into Python code?

I am trying to create an API that receives arguments from postman. The body of the api contains two arguments: { "db":"EUR", "env":"test" } I parsed these two arguments in the code as below: parser =…
Metadata
  • 2,127
  • 9
  • 56
  • 127
7
votes
2 answers

flask-restful - resource class for current request

THE QUESTION All of my app's routes are defined via flask-restful Resources. How can I find the resource object/class that is processing current request? WHY I WANT THIS I wanted to log all exceptions raised while processing requests. I connect to…
jbet
  • 452
  • 4
  • 12
7
votes
1 answer

How to send POST data to flask using Reactjs fetch

I'm very new to react and i'm trying to get a hold on how to properly use fetch. I have this python flask route I'm trying to hit from the back end which looks something like this: @app.route('/api/v1', methods=['POST']) def postTest(): if not…
abefroman
  • 139
  • 1
  • 6
7
votes
1 answer

Is there a way to get the full url in flask_restful from a resource

Say I have a Resource that does not do anything but returns the url to the console from app import api class StaticFiles(Resource): def get(self): return api.url_for(self) # this only provides the resource url if the request was…
Evren Bingøl
  • 1,306
  • 1
  • 20
  • 32
7
votes
2 answers

Retrieve query params with Flask-RESTful

I have a flask-RESTful endpoint defined by: class SearchEvents(Resource): def get(self, name, start_date, end_date): #do stuff api.add_resource(endpoints.SearchEvents, '/events///') I'm…
Toby Weed
  • 594
  • 2
  • 7
  • 20
7
votes
1 answer

react frontend connecting to flask backend Howto

I have a ReactJS front end and a flask backend and I am having difficulties making both talk to each other, particular sending form variables from the frontend to Flask. Given below is my front end code which runs on 127.0.0.1:3000 import ReactDOM…
lordlabakdas
  • 1,163
  • 5
  • 18
  • 33
7
votes
2 answers

Convert a list of numpy arrays to json for return from flask api

I have a dictinary in python like this: mydic = { 'x1': list_of_numpy_array, 'x2': a numpy_array, 'x3': a list_of_numpy_array, 'x4': a list_of_numpy_array } I want to send this dictionary from flask-api to the client which calss…
user3000968
  • 156
  • 1
  • 7
7
votes
1 answer

TypeError: is not JSON serializable

I am writing web service using restful flask. The below code giving me this error - TypeError: is not JSON serializable from flask import jsonify from flask_restful import Resource class Recipe(Resource): def get(self): return…
Codeformer
  • 2,060
  • 9
  • 28
  • 46
7
votes
4 answers

Flask Alchemy with Marshmallow returns empty JSON

I am trying to return a json data after query from my database using Flask Alchemy, and Flask Marshmallow However, my code somehow always returns empty JSON data. Here's my code : My View : @app.route('/customer/', methods=['GET']) def…
Jeremy
  • 2,516
  • 8
  • 46
  • 80
7
votes
3 answers

How can I use multiple inheritance with a metaclass?

I'm trying to register all the resources that I defined with Flask-RESTFUL using the registry pattern. from flask_restful import Resource class ResourceRegistry(type): REGISTRY = {} def __new__(cls, name, bases, attrs): new_cls =…
Ketouem
  • 3,820
  • 1
  • 19
  • 29
7
votes
1 answer

Flask-Restful taking over exception handling from Flask during non debug mode

I've used Flask's exception handling during development (@app.errorhander(MyException)) which worked fine even for exceptions coming from Flask-Restful endpoints. However, I noticed that when switching to debug=False, Flask-Restful is taking over…
orange
  • 7,755
  • 14
  • 75
  • 139