简体   繁体   中英

Does HTTPie have the equivalent of curl's -d option?

I want to query a REST API with HTTPie. I am usuale to do so with curl, with which I am able to specify maxKeys and startAfterFilename eg

curl --location --request GET -G \                                                                                                  
"https://some.thing.some.where/data/v1/datasets/mydataset/versions/2/files" \
-d maxKeys=100 \
-d startAfterFilename=YYYMMDD_HHMMSS.file \
--header "Authorization: verylongtoken"

How can I use those -d options in HTTPie?

In your case the command looks like this:

http -F https://some.thing.some.where/data/v1/datasets/mydataset/versions/2/files \
    Authorization:verylongtoken \
    startAfterFilename=="YYYMMDD_HHMMSS.file" \
    maxKeys=="100"

Although, there is a bunch of methods to pass some data with httpie . For example

http POST http://example.com/posts/3 \
    Origin:example.com \  # :   HTTP headers
    name="John Doe" \     # =   string
    q=="search" \         # ==  URL parameters (?q=search)
    age:=29 \             # :=  for non-strings
    list:='[1,3,4]' \     # :=  json
    file@file.bin \       # @   attach file
    token=@token.txt \    # =@  read from file (text)
    user:=@user.json      # :=@ read from file (json)

Or, in the case of forms

http --form POST example.com \
    name="John Smith" \
    cv=@document.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM