python-restx / flask-restx

Fork of Flask-RESTPlus: Fully featured framework for fast, easy and documented API development with Flask
https://flask-restx.readthedocs.io/en/latest/
Other
2.14k stars 333 forks source link

A way to use custom HTTP methods #574

Closed sergeyepimakhov closed 11 months ago

sergeyepimakhov commented 11 months ago

Ask a question Is there a way to use a custom HTTP method i.e. LIST among standard ones GET, POST etc.?

class MyClass(Resource):

    def list(self):
        return 'ok', 200

Currently we are getting back:

AttributeError: 'FlaskClient' object has no attribute 'list'

Additional context Flask overrides did't help: https://flask.palletsprojects.com/en/2.3.x/patterns/methodoverrides/

peter-doggart commented 11 months ago

flask-restx is designed to implement RESTful type APIs, so custom HTTP methods are not supported. There are also compatibility issues, because Swagger 2.0 that is currently used to generate the docs doesn't support custom methods either to my knowledge.

You shouldn't need a list function in a truly RESTful api, because GET on a resource with no identifier should return a list. For example: GET /products - Should return a list of all products. GET /products/ - Should return a specific product or 404 if not found.

sergeyepimakhov commented 11 months ago

Thank you for clarification!