HttpService

open class HttpService

HttpService provides the basic tools to construct URLs properly, and issue HTTP requests, especially those that yield a JSON response.

Constructors

Link copied to clipboard
constructor()
HttpService When using the default constructor, DEFAULT_CONNECT_TIMEOUT and DEFAULT_READ_TIMEOUT are used for the timeout values.
constructor(connectTimeout: Int, readTimeout: Int)
HttpService Provides overrides for the connection and read timeout values on instantiation.

Properties

Link copied to clipboard
Link copied to clipboard
Default connection timeout used by HttpService if none is given
Link copied to clipboard
Default read timeout used by HttpService if none is given
Link copied to clipboard
val HEADER_USER_AGENT: String = "User-Agent"
User Agent field value
Link copied to clipboard
open var readTimeout: Int
Link copied to clipboard
val TAG: String

Functions

Link copied to clipboard
open fun buildURIWithQueryParameters(baseUri: String, parameters: Map<String, Any>): URI
Convenience method to construct a URL object from a base URL string and a Map of query string parameters.
Link copied to clipboard
open fun doDeleteRequest(uri: URI, headers: Map<String, String>): String
Performs an HTTP PUT request using the given URI.
Link copied to clipboard
open fun doGetRequest(uri: URI): String
open fun doGetRequest(uri: URI, headers: Map<String, String>): String
Performs an HTTP GET request using the given URI.
Link copied to clipboard
open fun doImageGetRequest(uri: URI): Bitmap
open fun doImageGetRequest(uri: URI, maxWidth: Int, maxHeight: Int): Bitmap
Performs and HTTP GET request expecting a bitmap image file in the response.
Link copied to clipboard
open fun doJSONGetRequest(uri: URI): JSONObject
open fun doJSONGetRequest(uri: URI, headers: Map<String, String>): JSONObject
Performs an HTTP GET request assuming that the response body will contain a valid JSON document.
Link copied to clipboard
open fun doJSONPostRequest(uri: URI): JSONObject
open fun doJSONPostRequest(uri: URI, headers: Map<String, String>): JSONObject
Performs an HTTP POST request assuming that the response body will contain a valid JSON document.
open fun doJSONPostRequest(uri: URI, headers: Map<String, String>, requestBody: String): JSONObject
Link copied to clipboard
open fun doPostRequest(uri: URI): String
open fun doPostRequest(uri: URI, headers: Map<String, String>): String
Performs an HTTP POST request using the given URI.
Link copied to clipboard
open fun inputStreamToString(inputStream: InputStream): String
Reads all data from the given InputStream and converts to a String (Uses StringBuilder).
Link copied to clipboard
open fun parseToJSONObject(jsonString: String): JSONObject
Parses given string containing JSON data into a JSONObject which provides an interface for extracting JSON data.
Link copied to clipboard
open fun readerToString(reader: Reader): String
Reads all data from the given Reader and converts to a String (Uses StringBuilder).
Link copied to clipboard
open fun runDeleteRequest(uri: URI, headers: Map<String, String>): HttpResponse
This is the same as {doDeleteRequest} but returns a {{HttpResponse} instead.
Link copied to clipboard
open fun runGetRequest(uri: URI, headers: Map<String, String>): HttpResponse
This is the same as {doGetRequest} but returns a {{HttpResponse} instead.
Link copied to clipboard
Same as {doJSONGetRequest} but this returns a {{HttpResponse}} instead.
open fun runJSONGetRequest(uri: URI, headers: Map<String, String>): HttpResponse
Same as {doJSONGetRequest )}} but this returns a {{HttpResponse}} instead.
Link copied to clipboard
open fun runJSONPostRequest(uri: URI, headers: Map<String, String>): HttpResponse
Same as {doJSONPostRequest} but this returns a {{HttpResponse}} instead.
open fun runJSONPostRequest(uri: URI, headers: Map<String, String>, requestBody: String): HttpResponse
Link copied to clipboard
open fun runPostRequest(uri: URI, headers: Map<String, String>): HttpResponse
This is the same as {doPostRequest} but returns a {{HttpResponse} instead.