I am using ASP.NET Web API 2 with attribute routing.
I have the following PlayerModel
.
public class PlayerModel
{
public int Id {
Well, make sure that you specify raw
and set the Content-Type
request header to application/json
. And then go ahead and specify the body of the POST request that will match your view model structure:
{
"id": 1,
"key": "some key",
"name": "some name of course",
"password": "the hyper secret",
"teamId": 256,
"stat": {
"playerId": 115,
"firstName": "John",
"lastName": "Smith",
"title": "His Royal Majesty",
"emailAddress": "john.smith@buckingampalace.com",
"phoneNumbers": [
{ "value": "123", "extension": "05" },
{ "value": "456", "extension": "45" }
],
"teamId": 678
}
}
So your actual payload's gonna look like that at protocol level:
POST /NFL/Players HTTP/1.1
Host: localhost:9888
Content-Type: application/json
Content-Length: 582
{
"id": 1,
"key": "some key",
"name": "some name of course",
"password": "the hyper secret",
"teamId": 256,
"stat": {
"playerId": 115,
"firstName": "John",
"lastName": "Smith",
"title": "His Royal Majesty",
"emailAddress": "john.smith@buckingampalace.com",
"phoneNumbers": [
{ "value": "123", "extension": "05" },
{ "value": "456", "extension": "45" }
],
"teamId": 678
}
}