开发者

Json object to uri string in RESTful request (PHP)

开发者 https://www.devze.com 2023-04-12 09:55 出处:网络
What is the proper way to pass ambiguous parameters in a REST request url? var requestObj = { city: \'London\',

What is the proper way to pass ambiguous parameters in a REST request url?

var requestObj = {

city: 'London',

taxes: [

{ name: 'Income Tax', value: '10%', 'applies_to': 'paycheck'},

{ name: 'Sales Tax', value: '7.5%', 'applies_to': 'sa开发者_C百科les'}

]

}

How can I make that request to http://blah.com which will receive the request?

http://blah.com/city/london/taxes/Now What?

I have previously checked this php array in url from json and many more but to no avail.


What are you trying to do here? If you're adding a new entry, then in a RESTful API you'd use a POST request. This means that the parameters won't even appear in the URL.

If this is some sort of query, you could maybe send the parameters base64 encoded. It's not elegant, it's not even strictly RESTful, but it should work unless the URL becomes too long.

Edit: You could define your own serialization for the taxes array, something like .../Income Tax/10%/paycheck/Sales Tax/7.5%/sales (urlencoded, of course). Still not nice, but this and some kind of encoding (like base64) are the only things I can think of.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号