Skip to content
Advertisement

get request to accepts params in postman, currently sends a unsupported media type error

I’ve built different get methods using body request to select an id (with raw json). However, as I learned that get methods doesn’t support body request, I would like to change so that I can use params in postman insted. However, when I do it now, I get an 415 Unsupported Media Type.

Here’s the method:

Controller:

Interface class:

Before I sent requests in the body like:

But I would like to send it in the params insted so for example:

Anyone know how to achive this?

Advertisement

Answer

You can have method parameters bound to query parameters by using the [FromQuery] Attribute.

In your case, it should look something like this:

which will enable you to use <your controller path>/rentReason?rentreasonId=40


However, I’d recommend to use route parameters for this:

Which will get you something like <authority>/your/api/route/rentreason/40.

For reference: FromRouteAttribute

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement