5

I am using Mozilla fire fox add-on RESTClient to test my web-services. Up to this I was using POST method by setting header Content-Type:application/x-www-form-urlencoded and data separated by & in request body e.g. id=1&title=abc

But now I want to POST the JSON object to using the same service. The sample objects are as below :

[
    {
         "id": 4
         "type":"alpha", 
         "title":"Title1"
    }
]

OR

[
    {
         "id": 4
         "type":"alpha", 
         "title":"Alpha"
    },
    {
         "id": 5
         "type":"beta", 
         "title":"Beta"
    },
    {
         "id": 6
         "type":"gama", 
         "title":"Gama"
    }
]

OR

[
    {
        "id": 5,
        "type":"beta", 
        "title":"Sample beta", 
        "children":[{
                "id": 6,
                "type":"betachild", 
                "title":"Beta child 1"
            },
            {
                "id": 7,
                "type":"betachild", 
                "title":"Beta child 2"
            },
            {
                "id": 8,
                "type":"betachild", 
                "title":"Beta child 3"
            }
        ]
    }
] 

OR

[
    {
        "id": 5,
        "type":"beta", 
        "title":"Sample beta", 
        "children":[{
                "id": 6,
                "type":"betachild", 
                "title":"Beta child 1"
            },
            {
                "id": 7,
                "type":"betachild", 
                "title":"Beta child 2"
            },
            {
                "id": 8,
                "type":"betachild", 
                "title":"Beta child 3"
            }
        ]
    }, 
    {
        "id": 9,
        "type":"beta", 
        "title":"Sample gama", 
        "children":[{
                "id": 10,
                "type":"gamachild", 
                "title":"Gama child 1"
            },
            {
                "id": 11,
                "type":"gamachild", 
                "title":"Gama child 2"
            },
            {
                "id": 12,
                "type":"gamachild", 
                "title":"Gama child 3"
            }
        ]
    }
] 

How can I pass such JSON object in POST request using RESTClient add-on?

Dev
  • 6,570
  • 10
  • 66
  • 112
  • Why do you set header Content-Type:application/x-www-form-urlencoded? Can't you set json/xml? – Ushani Aug 13 '15 at 18:43
  • @Ushani Yes, I had set it and found it working OK. The only change I was required to do was set the header "Content-type:application/json". – Dev Aug 14 '15 at 04:38
  • Great! My typo as well. Just noticed. I wanted to mean application/json except json/xml. :) – Ushani Aug 14 '15 at 13:40

1 Answers1

13

Set the content type as Content-type:application/json

Ushani
  • 1,199
  • 12
  • 28