Sunday 18 August 2019

HTTPie: POST: post json payload to an api


Syntax
http POST {URL} key1=value1 key2=valu2.....keyN=valueN

Create new guest
http POST http://localhost:8080/public/v1/guests/ firstName=krishna lastName=maj

Above request is equivalent to below one.

POST /public/v1/guests/ HTTP/1.1
Accept: application/json, */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 43
Content-Type: application/json
Host: localhost:8080
User-Agent: HTTPie/1.0.2

{
    "firstName": "krishna",
    "lastName": "maj"
}
Example
$http POST http://localhost:8080/public/v1/guests/ firstName=krishna lastName=maj
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 11:12:40 GMT
Expires: 0
Pragma: no-cache
Transfer-Encoding: chunked
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block

{
    "firstName": "krishna",
    "id": 1,
    "lastName": "maj"
}


Get all the guests.

$http  http://localhost:8080/public/v1/guests/
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 11:35:40 GMT
Expires: 0
Pragma: no-cache
Transfer-Encoding: chunked
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block

[
    {
        "firstName": "krishna",
        "id": 1,
        "lastName": "maj"
    }
]



Previous                                                    Next                                                    Home

No comments:

Post a Comment