Showing posts with label HTTPie. Show all posts
Showing posts with label HTTPie. Show all posts

Sunday, 18 August 2019

HTTPie: Prompt for the password

If you provide only user name while accessing the secure API, HTTPie prompt you for the password.

Syntax
http -a {userName} {HTTP_METHOD} URL

$http -a krishna POST http://localhost:8080/api/v1/employees firstName=Krishna lastName=Gurram
http: password for krishna@localhost:8080: 
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:25:22 GMT
Expires: 0
Pragma: no-cache
Set-Cookie: JSESSIONID=429D5B133F1A5F4C15BD23C3939F0BD9; Path=/; HttpOnly
Transfer-Encoding: chunked
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block

{
    "firstName": "Krishna",
    "id": 6,
    "lastName": "Gurram"
}



Previous                                                    Next                                                    Home

HTTPie: Write both response headers and data to a file


Use --output and --print options to send both response header and body to a file.

Syntax
http --output={fileName} --print=hb {URL}

$http --output=out.txt --print=hb http://localhost:8080/public/v1/guests
$
$cat out.txt 
HTTP/1.1 200 
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Frame-Options: DENY
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Fri, 02 Aug 2019 15:21:41 GMT

[{"id":5,"firstName":"ram","lastName":"krishna"}]



Previous                                                    Next                                                    Home

HTTPie: Send response data to a file


Using --output option, you can send the response data to a file.


$http --output out.txt http://localhost:8080/public/v1/guests
$
$cat out.txt
[{"id":5,"firstName":"ram","lastName":"krishna"}]



Previous                                                    Next                                                    Home