ironcurtain
ironcurtain

Reputation: 690

REST API Post Object

I have an API Endpoint as below:

[HttpPost]
public async Task<IActionResult> Post([FromBody]Create command)
{
    await DispatchAsync(command);

    return Created($"Server/{command.Id}", null);
}

public class Create
{
    public string Ip { get; set; }
    public string Fqdn { get; set; }
    public string Comments { get; set; }
    public bool IsActive { get; set; }
    public string AddBy { get; set; }
    public DateTime AddDate { get; set; }
    public string LastUpdateBy { get; set; }
    public DateTime LastUpdateDate { get; set; }
}

Now, I would like to test is in SOAPUI or RESTClient (Mozilla extension). My problem is that when I set POST as:

"Create" :
{
    "Ip": "123",
    "Fqdn": "123",
    "Comments": "123",
    "IsActive": "TRUE",
    "AddBy": "test",
    "AddDate": "2017-01-01",
    "LastUpdateBy": "test",
    "LastUpdateDate": "2017-01-01"
}

in debugging mode my Create object passed to endpoint is null. Any idea how POST should look like?

Upvotes: 0

Views: 62

Answers (1)

Awanish
Awanish

Reputation: 367

Try removing the "Create:" part. Just post below json:

{
    "Ip": "123",
    "Fqdn": "123",
    "Comments": "123",
    "IsActive": "TRUE",
    "AddBy": "test",
    "AddDate": "2017-01-01",
    "LastUpdateBy": "test",
    "LastUpdateDate": "2017-01-01"
}

Also, please ensure your are setting "Content-type" as "application/json" in your request header.

Upvotes: 1

Related Questions