Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow nested empty routes for REST #1292

Open
lifinsky opened this issue May 15, 2020 · 4 comments
Open

Allow nested empty routes for REST #1292

lifinsky opened this issue May 15, 2020 · 4 comments

Comments

@lifinsky
Copy link

lifinsky commented May 15, 2020

/**
 * @Controller("backoffice/files")
 * @Middleware(JwtAuthMiddleware::class)
 */
class FilesController
{
    /**
     * @Inject(FileService::class)
     */
    private FileService $fileService;

    /**
     * @RequestMapping("/backoffice/files", method=RequestMethod::GET)
     * @Validate(FileValidator::class, type=ValidateType::GET, fields={"page"})
     *
     * @return array<string, mixed>
     */

Please allow route as "" for methods.
For example:

@RequestMapping("", method=RequestMethod::GET)

It should be resolved as GET "backoffice/files"

@github-actions github-actions bot added the swoft: validator issues for swoft validator component label May 15, 2020
@inhere inhere added suggestion swoft: http and removed swoft: validator issues for swoft validator component labels May 15, 2020
@inhere inhere added this to the v2.0.10 milestone May 15, 2020
@inhere inhere assigned inhere and unassigned stelin and JasonYHZ May 15, 2020
@inhere
Copy link
Member

inhere commented May 15, 2020

hi @lifinsky

At now, RequestMapping.route:

  • use "", eg: @RequestMapping("", method=RequestMethod::GET)
  • or use "@prefix", eg: @RequestMapping("@prefix", method=RequestMethod::GET)

Will use the route prefix(Controller.prefix) as route.

The update will release on next version v2.0.10

@lifinsky
Copy link
Author

lifinsky commented May 15, 2020

Currently it's not work

@RequestMapping("", method=RequestMethod::GET)
@RequestMapping("@prefix", method=RequestMethod::GET)

I have REST endpoint

GET /backoffice/files
GET /backoffice/files/{id}
POST /backoffice/files
PUT /backoffice/files/{id}
DELETE /backoffice/files/{id}

With {id} - all works.
For example:

    /**
     * @RequestMapping("{id}", method=RequestMethod::GET)
     * @Validate(FileValidator::class, type=ValidateType::PATH, fields={"id"})
     */
    public function get(int $id, Response $response): Response

But for "GET /backoffice/files" and "POST /backoffice/files" I was forced to use duplication.
For example:

    /**
     * @RequestMapping("/backoffice/files", method=RequestMethod::GET)
     * @Validate(FileValidator::class, type=ValidateType::GET, fields={"page"})
     *
     * @return array<string, mixed>
     */
    public function list(Request $request): array

@lifinsky
Copy link
Author

Sorry, I did not understand you. It will be in the next release. Thanks!!!

@inhere
Copy link
Member

inhere commented May 16, 2020

@lifinsky yes, will release on next version

inhere added a commit to swoft-cloud/swoft-http-server that referenced this issue Sep 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants