Home > Blockchain >  How to distinguish between two httpget parameters that accept same input argument?
How to distinguish between two httpget parameters that accept same input argument?

Time:10-17

[HttpGet("{id}")]
        public async Task<ActionResult<IEnumerable<SupplierInfo>>> GetItemsByRequestID(int RequestID)
        {
            var item = await this.supplierInfoRepository.GetItemByRequestID(RequestID);
            return Ok(item);
        }

        [HttpGet("{id}")]
        public async Task<ActionResult<IEnumerable<SupplierInfo>>> GetItems(int id)
        {
            var item = await this.supplierInfoRepository.GetItem(id);
            return Ok(item);
        }

I have two Httpget requests, How should I distinguish them because both are accepting an integer. One is GetItemByRequestID and other one is GetItems.

Should I change one to controller/requestid/id and the other one to controller/id

CodePudding user response:

If you have an Items controller then getting item by id might look like this

[HttpGet("{id}")]

and getting by specific request id

[HttpGet("GetItemsByRequestID/{RequestID}")]
  • Related