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
94
votes
3 answers

Flask-RESTful vs Flask-RESTplus

Other than the ability to automatically generate an interactive documentation for our API using Swagger UI, are there any real advantages of using Flask-RESTplus over Flask-RESTful?
masterforker
  • 2,443
  • 2
  • 25
  • 39
81
votes
4 answers

RuntimeError: working outside of application context

app.py from flask import Flask, render_template, request,jsonify,json,g import mysql.connector app = Flask(__name__) class TestMySQL(): @app.before_request def before_request(): try: g.db =…
guri
  • 1,521
  • 2
  • 14
  • 20
62
votes
4 answers

flask restful: passing parameters to GET request

I want to create a resource that supports GET request in following way: /bar?key1=val1&key2=val2 I tried this code, but it is not working app = Flask(__name__) api = Api(app) class BarAPI(Resource): def get(key1, key2): return…
Rugnar
  • 2,894
  • 3
  • 25
  • 29
49
votes
9 answers

Flask RESTful cross-domain issue with Angular: PUT, OPTIONS methods

I've developed a small write-only REST api with Flask Restful that accepts PUT request from a handful of clients that can potentially have changing IP addresses. My clients are embedded Chromium clients running an AngularJS front-end; they…
rgb
  • 3,144
  • 3
  • 17
  • 26
45
votes
3 answers

Flask-RESTful API: multiple and complex endpoints

In my Flask-RESTful API, imagine I have two objects, users and cities. It is a 1-to-many relationship. Now when I create my API and add resources to it, all I can seem to do is map very easy and general URLs to them. Here is the code (with useless…
user2497586
36
votes
4 answers

Python Flask-Restful POST not taking JSON arguments

I am very new to Flask (& Flask-Restful). My problem : json arguments for a POST is getting set to NONE (not working). I am able to take arguments from the form-data, using POSTMAN plugin for chrome. But, when i switch to raw (& feed a json), it…
sudhishkr
  • 3,318
  • 5
  • 33
  • 55
34
votes
5 answers

Flask API TypeError: Object of type 'Response' is not JSON serializable

i have a problem with Python Flask Restful API and data goes to Elasticsearch, when i post a new data with Postman, problem is: TypeError: Object of type 'Response' is not JSON serializable Can you help me? Model: from marshmallow import Schema,…
webteroyal
  • 341
  • 1
  • 3
  • 5
34
votes
8 answers

Nested validation with the flask-restful RequestParser

Using the flask-restful micro-framework, I am having trouble constructing a RequestParser that will validate nested resources. Assuming an expected JSON resource format of the form: { 'a_list': [ { 'obj1': 1, …
Daniel Naab
  • 22,690
  • 8
  • 54
  • 55
31
votes
5 answers

How to apply integration tests to a Flask RESTful API

[As per https://stackoverflow.com/a/46369945/1021819, the title should refer to integration tests rather than unit tests] Suppose I'd like to test the following Flask API (from here): import flask import flask_restful app =…
Kurt Peek
  • 52,165
  • 91
  • 301
  • 526
31
votes
7 answers

Custom error message json object with flask-restful

It is easy to propagate error messages with flask-restful to the client with the abort() method, such as abort(500, message="Fatal error: Pizza the Hutt was found dead earlier today in the back seat of his stretched limo. Evidently, the notorious…
Derek
  • 3,295
  • 3
  • 24
  • 31
28
votes
3 answers

Flask-restful API Authorization. Access current_identity inside decorator

I use flask-restful to create my APIs. I have used flask-jwt for enabling authentication based on JWT. Now I need to do authorization. I have tried putting my authorization decorator. test.py (/test api) from flask_restful import Resource from…
Hussain
  • 5,057
  • 6
  • 45
  • 71
28
votes
6 answers

Flask-RESTful - Upload image

I was wondering on how do you upload files by creating an API service? class UploadImage(Resource): def post(self, fname): file = request.files['file'] if file: # save image else: # return error …
Sigils
  • 2,492
  • 8
  • 24
  • 36
25
votes
6 answers

How to use Flask-Cache with Flask-Restful

How do I use Flask-Cache @cache.cached() decorator with Flask-Restful? For example, I have a class Foo inherited from Resource, and Foo has get, post, put, and delete methods. How can I can invalidate cached results after a…
cyberra
  • 579
  • 1
  • 6
  • 14
22
votes
2 answers

Flask - access the request in after_request or teardown_request

I want to be able to access the request object before I return the response of the HTTP call. I want access to the request via "teardown_request" and "after_request": from flask import Flask ... app = Flask(__name__,…
Lin
  • 2,445
  • 5
  • 27
  • 37
22
votes
3 answers

Flask-RESTful - Return custom Response format

I have defined a custom Response format as per the Flask-RESTful documentation as follow. app = Flask(__name__) api = restful.Api(app) @api.representation('application/octet-stream') def binary(data, code, headers=None): resp =…
Ayrx
  • 2,092
  • 5
  • 26
  • 34
1
2 3
99 100