Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-15093] Use data parameter for GET request in httpclient too

GitHub Issuen/a
TypeNew Feature
PriorityLow
StatusOpen
ResolutionUnresolved
Affected Version/sRelease 3.1.2
Fix Version/sn/a
ComponentsiOS
Labelsn/a
ReporterKevin Purnelle
AssigneeUnknown
Created2013-08-06T14:16:02.000+0000
Updated2018-02-28T20:04:27.000+0000

Description

Hello, At this time, it's possible to pass a data argument to httpClient.send method for POST request. (an object will be serialized) I don't know if people would need the following but I found it useful. I didn't want to concatenate params to url by hand anymore, for GET requests. A more elegant solution was to create a simple function that would do the same for GET request as you do for POSTs. For example at this time I do the following:
var reqUrl = http://api.whatever.com/users/search.json
var params = { age: 25, sex: male }
...
xhr.open('GET', reqUrl + paramsToUrl(params))
xhr.send()
This results in the following request: http://api.whatever.com/users/search.json?age=25&sex=male It would be nice to have this supported natively by titanium. So doing this:
xhr.open('GET', reqUrl)
xhr.send(params)
would have the same result as my function. I think this adds some nice abstraction and a clearer code. What do you think?

Comments

  1. Stephen Feather 2013-08-06

    Let me see if I understand you correctly... You want to change the [xmlHTTPRequest Object ](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) so the SEND method will QS your params automatically for you?
  2. Kevin Purnelle 2013-08-06

    I often had code like this:
       var searchParams = {
           age: $.ageField.value,
           sex: $.sexField.value
       }
       
       
       var request = 'http://api.whatever.com/users/search.json?age=' + searchParams.age + '&sex=' + searchParams.sex
       
       xhr.open('GET', request)
       xhr.send()
       
    Instead I wish we could do that:
       var searchParams = {
           age: $.ageField.value,
           sex: $.sexField.value
       }
       
       xhr.open('GET', 'http://api.whatever.com/users/search.json')
       xhr.send(searchParams)
       
    It's similar to POST request syntax, and nicer. (o maybe there is something I don't know that could improve what I do)

JSON Source