Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call asp.net core web api from PostMan

I am trying to call following function (asp.net web api core) from PostMan:

[HttpPost]
public InfluencerSearchResultWithFacets Post(string q, string group, List<string> subGroups)
{
   return GetSearchResult("",null,null);
}

But I get following error: A non-empty request body is required

I have setup PostMan like this: enter image description here

enter image description here

I also tried adding to body: enter image description here

like image 916
Thomas Segato Avatar asked Nov 24 '18 22:11

Thomas Segato


People also ask

How can I call ASP Net Web API from Postman?

From Postman tool - right pane select GET from DropDown, then enter your Web API url like http://localhost:<portnumber>/api/supplier and click on Send button. This will make a request to Web API server and get response. You can get response in JSON, XML, HTML, Text format.

Does ASP NET core have Web API?

ASP.NET Core supports creating web APIs using controllers or using minimal APIs. Controllers in a web API are classes that derive from ControllerBase. This article shows how to use controllers for handling web API requests.


1 Answers

So you can create a model like

public class Model
{
  public string q { get; set; }
  public string group { get; set; }
  public List<string>subGroups { get; set; }
}

and use it

[HttpPost]
public InfluencerSearchResultWithFacets Post([FromBody] Model model)
{
   return GetSearchResult("",null,null);
}

enter image description here

This is if you fit Json format. Also you can leave some parameters in URL and other pass as a body like

[HttpPost]
public InfluencerSearchResultWithFacets Post([FromUri]string q, [FromUri]string group, [FromBody]List<string> subGroups)
{
   return GetSearchResult("",null,null);
}

enter image description here

like image 142
Roman Marusyk Avatar answered Oct 03 '22 10:10

Roman Marusyk