NativeScript plugin for OkHttp
OkHttp is an HTTP client that supports:
- HTTP/2 and SPDY support allows all requests to the same host to share a socket.
- Connection pooling reduces request latency (if SPDY isn’t available).
- Transparent GZIP shrinks download sizes.
- Response caching avoids the network completely for repeat requests.
Installation
Run the following command from the root of your project:
$ tns plugin add nativescript-okhttp
This command automatically installs the necessary files, as well as stores nativescript-okhttp as a dependency in your project's package.json
file.
Usage
To use the social share module you must first require()
it. After you require()
the module you have access to its APIs.
var okHttp = ;
API
getString(url)
The getString()
method downloads a URL as a string.
var okHttp = ;{var result = okHttp;console;}exportspageLoaded = pageLoaded;
getJSON(url)
The getString()
method downloads a URL as a string.
var okHttp = ;{var json = okHttp;console;}exportspageLoaded = pageLoaded;
getImage(url)
The getImage()
method returns an image as a stream from a remote URL.
In this example, we will download an image from umgur (http://i.imgur.com/sXG9IHW.jpg) and we will share it ot Facebook using a social share plugin by @tjvantoll (https://github.com/tjvantoll/nativescript-social-share).
var socialShare = ;var imageSource = ;var okHttp = ;{var inputStream = okHttp;var image = imageSource;socialShare;}exportspageLoaded = pageLoaded;