How to send json data request to api use Postman or Swager

In postman:
Set header Content-Type to application/json
Set body request type to raw, content must be json format, eg.
{
"msg":{"address": {"street": "end", "number": 31, "road": 2, "suburb": "hillcrest"},
"price": 23380,"on_market_time": "2018-09-03T19:42:19.296591"}
}

In Swager:
By default, the Content-Type is already set to application/json
Set body value must be json format, eg.
{
"msg":{"address": {"street": "end", "number": 31, "road": 2, "suburb": "hillcrest"},
"price": 23380,"on_market_time": "2018-09-03T19:42:19.296591"}
}

How to get the value in Laravel API:

parameter msg will be an array like below:
array(3) {
["address"]=>
array(4) {
["street"]=>
string(3) "end"
["number"]=>
int(31)
["road"]=>
int(2)
["suburb"]=>
string(9) "hillcrest"
}
["price"]=>
int(23380)
["on_market_time"]=>
string(26) "2018-09-03T19:42:19.296591"
}

If necessary, we can convert the nested array to object by :
$msg_obj = json_decode(json_encode($msg), FALSE);

CURL command line example:

curl -X POST --header "Content-Type: application/json" --header "Accept: application/json" -d "{
\"msg\":{\"address\": {\"street\": \"end\", \"number\": 31, \"road\": 2, \"suburb\": \"hillcrest\"},
\"price\": 23380,\"on_market_time\": \"2018-09-03T19:42:19.296591\"}
}
" "http://localhost/api/v1/jsonTest"

Leave a Reply

Your email address will not be published. Required fields are marked *