Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

293
Views
How to deal with NestJS @Get() decorator?

This block of code works properly. I'm able to access both functions with the URL http://localhost:3000/vehicle/availableVehicles & http://localhost:3000/vehicle/1 accordingly

    @Controller('vehicle')
    export class VehicleController {
        constructor(
            private readonly vehicleService: VehicleService,
            private readonly crudService: CurdService
        ) { }
        tableName: string = 'vehicle';
    
        @Get('availableVehicles')
        async availableVehicles() {
            return await this.vehicleService.availableVehicles();
        }
        
        @Get(':id')
        async getbyId(@Req() request: Request) {
            return await this.crudService.getById(this.tableName, request.params.id);
        }
  }

But when I just swap between the 2 functions like code block below then the function availableVehicles() doesn't work & the URL http://localhost:3000/vehicle/availableVehicles hits the getbyId() function. What to do? Or what I'm doing wrong? Thanks in advance.

    @Controller('vehicle')
    export class VehicleController {
        constructor(
            private readonly vehicleService: VehicleService,
            private readonly crudService: CurdService
        ) { }
        tableName: string = 'vehicle';

        @Get(':id')
        async getbyId(@Req() request: Request) {
            return await this.crudService.getById(this.tableName, request.params.id);
        }
    
        @Get('availableVehicles')
        async availableVehicles() {
            return await this.vehicleService.availableVehicles();
        }
  }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You just do exactly what you did in the first example, put the more specific routes above the ones that take route parameters.

When the server's routing table is being built on application startup they will be discovered and registered in this order.

This is a duplicate of https://stackoverflow.com/a/68727403/1364771

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!