Rgnr
Rgnr

Reputation: 21

ASP.NET Core Invoke API via Postman

So i have this ASP.NET Core on my local machine, i have installed the prerequisites and after running the application locally, the response was correct from the web browset that it was not found.

Okay, i am trying to invoked this API via Postman and i couldnt determine why i cant access it though i already checked the routings.

Below is the sample template

[HttpGet]
    [Route("Details")]
    public async Task<IActionResult> GetDetails(string value = null)
    {
        var response = new ListModelResponse<SomeModel>() as IListModelResponse<SomeModel>;

        try
        {
            response.Model = await GetDetailsRepository
                    .GetDetailsSS(value)
                    .Select(item => item.ToViewModel())      
                    .OrderBy(item => item.Name)
                    .ToListAsync();
        }
        catch (Exception ex)
        {
            response.DidError = true;
            response.ErrorMessage = ex.Message;
        }

        return response.ToHttpResponse();
    }

And in application insights of visual studio, i can see that it is invoking the API but it seems it can't get through. Check this insights snippet

Other API's are working fine, it seems that i am missed something that i can't figure out right now.

For the routing i have this.

[Route("api/[controller]")]

I have also checked the Token and as i parsed it, i am getting the required info to access this API.

Thanks Lads!

Upvotes: 0

Views: 1567

Answers (2)

Bob Ash
Bob Ash

Reputation: 897

This error is due to the incorrect url present in the request. The correct URL has to be https://localhost:44309/api/your-controller-name/Details?value=CAT

ie. If the Controller name is ProductsController, then the URL has to be https://localhost:44309/api/Products/Details?value=CAT.

[Route("api/[controller]")]
public class ProductsController : Controller
{
   [HttpPost("Details")]     
    public async Task<IActionResult> GetDetails(string value = null)
    {
        ...
    }
}

Upvotes: 1

Bogdan Nedelcu
Bogdan Nedelcu

Reputation: 88

It doesn't seem that you have the name of the controller in the request url.

api/[controller]/Details?value=CAT...

Upvotes: 1

Related Questions