sanic-org / sanic

Accelerate your web app development | Build fast. Run fast.

Home Page:https://sanic.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The RESTful API has redundant path parameters

jsonvot opened this issue · comments

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

The RESTful API of the post method should not have the last path argument appear
image

Code snippet

from sanic import Sanic
from sanic.blueprints import Blueprint
from sanic.request import Request
from sanic.response import json
from sanic.views import HTTPMethodView

app = Sanic(__name__)
app.config.update({
    'OAS_UI_DEFAULT': 'swagger'
})


class UserView(HTTPMethodView):
    middleware = []

    async def get(self, request: Request):
        return json({'code': 200})

    async def post(self, request: Request):
        return json({'code': 200})

    async def put(self, request: Request):
        return json({'code': 200})

    async def delete(self, request: Request):
        return json({'code': 200})


user_bp = Blueprint('user_bp')
user_bp.add_route(UserView.as_view(), '/api/user/<user_id:int>')

app.blueprint(user_bp)

Expected Behavior

No response

How do you run Sanic?

Sanic CLI

Operating System

Linux

Sanic Version

23.12.1

Additional context

No response

Just out of curiosity - why it is redundant?

POST method may have a path argument when we want to explicitly name a resource or to assign a specific id, in some cases it could be even mandatory.