简体   繁体   中英

Issues in testing REST API with httpie

I have created an API for CURD operation in Django REST from Rest browsable API I can view/update/delete records . But when I trie dto perform update via httpie it doesn't work.

Url - > http://localhost:8000/api/user/profile/1/

Result from browser->

 {
    "user": 3,
    "subject": [
        1,
        3,
        4
    ],
    "phone": "897897897",
    "address": "xcgsajgchagclkk"
}

httpie reques -> http PUT http://localhost:8000/api/user/profile/1/ user=3 subject=[1,2] phone=333 address=my

Error ->

{
    "subject": [
        "Expected a list of items but got type \"unicode\"."
    ]
}

As we can see the error is in format of data sent in request but I am sending the list in subject [1,2] . So why its giving the error.

Edit : Header of my request

HTTP/1.0 400 BAD REQUEST
Allow: GET, PUT, PATCH, DELETE, HEAD, OPTIONS
Content-Type: application/json
Date: Fri, 30 Oct 2015 05:33:58 GMT
Server: WSGIServer/0.1 Python/2.7.6
Vary: Accept, Cookie
X-Frame-Options: SAMEORIGIN

As @BogdanIulianBursuc suggested in his comments Httpie use differnet syntax for submitting lists.

So the right syntax would be subject:='[1,2]'

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