1

I am creating a web api that needs to accept JSON as input that is sent by the called client side application. Below is the Code

 public class SetNameController : ApiController
 {
 [HttpPost]
 public async Task<IHttpActionResult> Get([FromBody] CodeDTO.RootObject bCode)
 {
 string Bar_Code = bCode.Barcode.ToString();
 if (Bar_Code == "" || Bar_Code == null)
 { 
 ....
 return OK(response)
 }

Here I am not sure How the client application call this Web API, the URL can be just like http://localhost:41594/api/SetName can it accept the JSON? Also can I test this using PostMan or Fiddler?

asked Oct 31, 2017 at 17:50
2
  • 2
    Should be '/api/SetName/Get'. Pass the bCode parameter formatted as JSON in the request body. As a side note naming the action 'Get' but decorating it with '[HttpPost]' is confusing. Commented Oct 31, 2017 at 17:59
  • Show the screen of the postman Commented Oct 31, 2017 at 18:00

1 Answer 1

2

Specify the following:

  • Method: POST
  • Header: Content Type

enter image description here

Then, provide the payload json data in Body as raw:

enter image description here

Also, change the name of the action Get which might cause confusion. If you still cannot hit your api, you can use route urls by decorating the action with [Route('yourURL')] attribute and change that accordingly in postman.

answered Oct 31, 2017 at 18:02
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.