The Http client is a non visual (don't appear in the screen at runtime) control that allows to made HTTP request from the app, so we can get information from a remote server, as well to upload information to it. It's a fundamental piece of the client apps, because, allows to download and upload remote information to be used in the app.
No matter what server software or server database is used, what the app do are HTTP calls with the right arguments, in order to retrieve information, and, in a similar way, made HTTP calls, with the right arguments, to upload information to the server, for example, to be inserted in a database: the client app is completely abstracted from what server software nor server database is used.
The Http client control put at your disposition the below designtime properties or variables. Designtime means here that these properties are only available in designtime and not in runtime.
The Http client control put at your disposition the below runtime properties or variables. You can set almost all these variables in designtime, and, they are also available to be use when the app is running. Note that we named here these variables in a capitalized way, because is like you can see it in the designtime control's inspector, however, at runtime we use the lower camel case way.
The Http client control put at your disposition the below methods. You can use these methods in runtime in order to perform various control related tasks.
The Http client control put at your disposition the below events handlers:
Designtime. Integer variable. The Top property stores the top position of the control in pixels. This value is only take in consideration at designtime, since this is a non visual control, which do not appear in the screen at runtime.
Designtime. Integer variable. The Left property stores the left position of the control in pixels. This value is only take in consideration at designtime, since this is a non visual control, which do not appear in the screen at runtime.
Designtime. Integer variable. The Width property stores the width of the control in pixels. This value is only take in consideration at designtime, since this is a non visual control, which do not appear in the screen at runtime.
Designtime. Integer variable. The Height property stores the height of the control in pixels. This value is only take in consideration at designtime, since this is a non visual control, which do not appear in the screen at runtime.
Designtime. Boolean variable. The Locked property determines if the control can be moved or resized in app view designer or not. Set a "false" value mean the control can be moved and resized. Set a "true" value (by default) mean the control cannot be moved nor resized. Remember that this control property is only for designtime and is not available in runtime.
Runtime. String variable. The Name control property stores the name of the Http client control as you set in designtime. The Name property value must be unique for the same app view, dialog or frame, that is, it's possible to have more than one "http1" in the app, if that controls resides in different app views, dialogs or frames. Note that you must consider this variable as read only: change the name of a control in runtime can cause unexpected results.
Runtime. String variable. The Url control property stores the URL that is used when you made the HTTP call, by using the control execute() method. You can change the Url property at runtime anytime you need: the latest one is used when the next HTTP call is made.
Runtime. String variable. The Method control property stores the HTTP method to be used when execute the HTTP call. You can use one of the "app.httpMethod.*" constants values to set this variable.
Runtime. Boolean variable. The Cache control property determines if the HTTP call server response must be cached or not. This variable is "false" by default, but you can set it to "true" in order to cache the server response of the HTTP call.
Runtime. String variable. The ContentType control property determines how the data is send to the server. Default is "application/x-www-form-urlencoded", which is fine for most cases. Note: For cross-domain requests, setting the content type to anything other than "application/x-www-form-urlencoded", "multipart/form-data", or "text/plain" will trigger the browser to send a preflight OPTIONS request to the server. You can set this variable to "false" in order to not send any content type to the server.
Runtime. String variable. The ResponseType control property determines how the response is retrieved from the server. The default value is an empty string: no specific response type. Set it to "blob" in order to deal with the response server's as a blob. This last one can be useful to download files and then store it into the user's device using the app.cordova.file.writeFile() method.
Runtime. Number variable. The Timeout control property can be established to a number of milliseconds to be taken as the HTTP call timeout. This variable is "0" (zero) by default, means no timeout is established.
Runtime. String variable. The UserName control property can be established to set the user name to be used in a basic HTTP call authentication.
Runtime. String variable. The Password control property can be established to set the user password to be used in a basic HTTP call authentication.
Runtime. Mixed variable. The Response control property stores the response retrieved from the server for the made HTTP call. This property is available in both the control Done event and the Fail event. The Response variable can be whatever the server send to the app, as simple as a string, or a more or less complex JSON object ready to be used by the app.
Runtime. Number variable. The StatusCode control property stores HTTP code of the made HTTP call. This property is available in both the control Done event and the Fail event.
Runtime. Mixed variable. The TextStatus control property stores the text status of the HTTP call after has been made. This property is available in both the control Done event and the Fail event. Possible values for the TextStatus variable (besides "null") can be "timeout", "error", "abort" and "parsererror". When an HTTP error occurs, the ErrorThrown property receives the textual portion of the HTTP status, such as "Not Found" or "Internal Server Error."
Runtime. String variable. The ErrorThrown control property stores the text status of the HTTP call after has been made. This property is available in the control Fail event. Possible values for this variable are "Not Found" or "Internal Server Error."
Runtime. Object variable. The Request control property stores the "jQuery Xhr" object that has been used to made the HTTP call. This property is available in both the control Done event and the Fail event
Runtime method. You can use this Http control method to execute an HTTP call. See below how easy is to use the control Data property to set the arguments for the HTTP call. After the execute method is called and when we get the server response, the control Done event or the control Fail event are fired.
Runtime method. You can use this Http control method to set an specific HTTP header to be send with the HTTP call. This method admits the below arguments, both of them required:
Name | Type | Description |
---|---|---|
headerName | String | The header name to be established for the HTTP call. |
headerValue | String | The header value to be established for the HTTP call. |
The Done event handler is fired when the HTTP call has been executed and the server response is ready for the app. The server response is available in the control Response property and you have the HTTP status code in the Status property.
The Fail event handler is fired if an error occurs. The server response is available in the control Response property and you have the HTTP status code in the Status property. Look also at the ErrorThrown property.
The below JavaScript variables are available in all the referred Http client control events handlers:
Name | Type | Description |
---|---|---|
self | Object | Stores the control object. This is a shortcut to the control variable, and it's available since we are talking about specific control events. |
view | Object |
Stores the current app view or dialog. This variable allow us to access to that view or dialog properties and methods and also their controls properties and methods. For example, you can access to a control properties using the variable "view.yourControlName", suposing the control is named "yourControlName". |
views | Object | Stores all the loaded app views. Note that loaded views mean that the app views has been previously show to the user. It's possible to access to the app view controls properties like "views.view1.yourControlName", suposing the view is named "view1" and the control is named "yourControlName". In the same way we can access to other controls of the view and to other loaded views and their controls. |
frames | Object | Stores all the app frames. You can use this variable to access to all the app frames and their controls. |
dialogs | Object | Stores all the app dialogs. You can use this variable to access to all the app dialogs and their controls. |
app | Object | Stores all the app properties and methods. You can use this variable to access to all the app properties and app methods. |