Sunday 18 August 2019

HTTPie: Specify nested json object

Using <<< operator, you can pass nested json payload.

Example
http -v POST http://localhost:8080/public/aboutUs <<< '{"address": { "city": "Bangalore", "country": "India", "state": "Karnataka","street": "Cho street" },"establishedYear": 2019, "name": "ABC Corp"}'

$http -v POST http://localhost:8080/public/aboutUs <<< '{"address": { "city": "Bangalore", "country": "India", "state": "Karnataka","street": "Cho street" },"establishedYear": 2019, "name": "ABC Corp"}'
POST /public/aboutUs HTTP/1.1
Accept: application/json, */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 146
Content-Type: application/json
Host: localhost:8080
User-Agent: HTTPie/1.0.2

{
    "address": {
        "city": "Bangalore",
        "country": "India",
        "state": "Karnataka",
        "street": "Cho street"
    },
    "establishedYear": 2019,
    "name": "ABC Corp"
}

HTTP/1.1 201 
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Content-Type: application/json;charset=UTF-8
Date: Fri, 02 Aug 2019 15:10:35 GMT
Expires: 0
Pragma: no-cache
Transfer-Encoding: chunked
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block

{
    "address": {
        "city": "Bangalore",
        "country": "India",
        "state": "Karnataka",
        "street": "Cho street"
    },
    "establishedYear": 2019,
    "name": "ABC Corp"
}

$
$
$
$http http://localhost:8080/public/aboutUs
HTTP/1.1 200 
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Content-Type: application/json;charset=UTF-8
Date: Fri, 02 Aug 2019 15:10:42 GMT
Expires: 0
Pragma: no-cache
Transfer-Encoding: chunked
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block

{
    "address": {
        "city": "Bangalore",
        "country": "India",
        "state": "Karnataka",
        "street": "Cho street"
    },
    "establishedYear": 2019,
    "name": "ABC Corp"
}


Previous                                                    Next                                                    Home

No comments:

Post a Comment