I have several general purpose routes
in my API
:
...
/api/general/user_types
/api/general/dlc_types
...
I want to have the GET
method opened for all users without JWT token
, but the POST
, PUT
and DELETE
methods only accessible when the JWT token
is included in the request.
The problem is that all these methods are allowed on the same route and I serve a different function based on the request method - GET = read
, POST = create
, PUT = update
, DELETE = delete
.
Any way to do this without separating the GET
method into a separate route?
Here is how my routes are declared:
@general_api.route("/user_types", methods=["GET", "POST", "PUT", "DELETE"])
@jwt_required()
def user_types_crud():
instance = ConstantsRoutes(UserTypes, "type")
return crud_routes(request, instance)
The ConstantsRoute
builds a CRUD
class for the UserTypes
table (SQLAlchemy
model), and the crud_routes
function takes a look at the request.method
and returns the proper method
(create
|read
|update
|delete
).