@ionic-native/http
- Version 5.36.0
- Published
- 126 kB
- 1 dependency
- MIT license
Install
npm i @ionic-native/http
yarn add @ionic-native/http
pnpm add @ionic-native/http
Overview
Ionic Native - Native plugins for ionic apps
Index
Variables
Classes
HTTPOriginal
- abort()
- clearCookies()
- delete()
- deleteSync()
- downloadFile()
- downloadFileSync()
- ErrorCode
- get()
- getBasicAuthHeader()
- getCookieString()
- getDataSerializer()
- getFollowRedirect()
- getHeaders()
- getRequestTimeout()
- getSync()
- head()
- headSync()
- options()
- optionsSync()
- patch()
- patchSync()
- post()
- postSync()
- put()
- putSync()
- removeCookies()
- sendRequest()
- sendRequestSync()
- setCookie()
- setDataSerializer()
- setFollowRedirect()
- setHeader()
- setRequestTimeout()
- setServerTrustMode()
- uploadFile()
- uploadFileSync()
- useBasicAuth()
Interfaces
Variables
variable HTTP
const HTTP: HTTPOriginal;
Classes
class HTTPOriginal
class HTTPOriginal extends IonicNativePlugin {}
HTTP Cordova / Phonegap plugin for communicating with HTTP servers. Supports iOS and Android.
Advantages over Javascript requests: - SSL / TLS Pinning - CORS restrictions do not apply - Handling of HTTP code 401 - read more at [Issue CB-2415](https://issues.apache.org/jira/browse/CB-2415)
import { HTTP } from '@ionic-native/http/ngx';constructor(private http: HTTP) {}...this.http.get('http://ionic.io', {}, {}).then(data => {console.log(data.status);console.log(data.data); // data received by serverconsole.log(data.headers);}).catch(error => {console.log(error.status);console.log(error.error); // error message as stringconsole.log(error.headers);});HTTPResponse
property ErrorCode
readonly ErrorCode: { GENERIC: number; SSL_EXCEPTION: number; SERVER_NOT_FOUND: number; TIMEOUT: number; UNSUPPORTED_URL: number; NOT_CONNECTED: number; POST_PROCESSING_FAILED: number; ABORTED: number;};
This enum represents the internal error codes which can be returned in a HTTPResponse object.
Modifiers
@readonly
method abort
abort: (requestId: string) => Promise<AbortedResponse>;
Parameter requestId
The RequestId of the request to abort
method clearCookies
clearCookies: () => void;
Clear all cookies.
method delete
delete: (url: string, parameters: any, headers: any) => Promise<HTTPResponse>;
Make a DELETE request
Parameter url
The url to send the request to
Parameter parameters
Parameters to send with the request
Parameter headers
The headers to set for this request
Returns
{Promise} returns a promise that will resolve on success, and reject on failure
method deleteSync
deleteSync: ( url: string, parameters: any, headers: any, success: (result: HTTPResponse) => void, failure: (error: any) => void) => string;
Make a sync DELETE request
Parameter url
The url to send the request to
Parameter parameters
Parameters to send with the request
Parameter headers
The headers to set for this request
Parameter success
A callback that is called when the request succeed
Parameter failure
A callback that is called when the request failed
Returns
{string} returns a string that represents the requestId
method downloadFile
downloadFile: ( url: string, body: any, headers: any, filePath: string) => Promise<any>;
Parameter url
The url to send the request to
Parameter body
The body of the request
Parameter headers
The headers to set for this request
Parameter filePath
The path to download the file to, including the file name.
Returns
{Promise} returns a FileEntry promise that will resolve on success, and reject on failure
method downloadFileSync
downloadFileSync: ( url: string, body: any, headers: any, filePath: string, success: (result: any) => void, failure: (error: any) => void) => string;
Parameter url
The url to send the request to
Parameter body
The body of the request
Parameter headers
The headers to set for this request
Parameter filePath
The path to download the file to, including the file name.
Parameter success
A callback that is called when the request succeed
Parameter failure
A callback that is called when the request failed
Returns
{string} returns a string that represents the requestId
method get
get: (url: string, parameters: any, headers: any) => Promise<HTTPResponse>;
Make a GET request
Parameter url
The url to send the request to
Parameter parameters
Parameters to send with the request
Parameter headers
The headers to set for this request
Returns
{Promise} returns a promise that will resolve on success, and reject on failure
method getBasicAuthHeader
getBasicAuthHeader: ( username: string, password: string) => { Authorization: string };
This returns an object representing a basic HTTP Authorization header of the form.
Parameter username
Username
Parameter password
Password
Returns
{Object} an object representing a basic HTTP Authorization header of the form {'Authorization': 'Basic base64EncodedUsernameAndPassword'}
method getCookieString
getCookieString: (url: string) => string;
Resolve cookie string for given URL.
Parameter url
method getDataSerializer
getDataSerializer: () => string;
Get the name of the data serializer which will be used for all future POST and PUT requests.
Returns
{string} returns the name of the configured data serializer
method getFollowRedirect
getFollowRedirect: () => boolean;
Resolve if it should follow redirects automatically.
Returns
{boolean} returns true if it is configured to follow redirects automatically
method getHeaders
getHeaders: (host: string) => string;
Get all headers defined for a given hostname.
Parameter host
The hostname
Returns
{string} return all headers defined for the hostname
method getRequestTimeout
getRequestTimeout: () => number;
Get global request timeout value in seconds.
Returns
{number} returns the global request timeout value
method getSync
getSync: ( url: string, parameters: any, headers: any, success: (result: HTTPResponse) => void, failure: (error: any) => void) => string;
Make a sync GET request
Parameter url
The url to send the request to
Parameter parameters
Parameters to send with the request
Parameter headers
The headers to set for this request
Parameter success
A callback that is called when the request succeed
Parameter failure
A callback that is called when the request failed
Returns
{string} returns a string that represents the requestId
method head
head: (url: string, parameters: any, headers: any) => Promise<HTTPResponse>;
Make a HEAD request
Parameter url
The url to send the request to
Parameter parameters
Parameters to send with the request
Parameter headers
The headers to set for this request
Returns
{Promise} returns a promise that will resolve on success, and reject on failure
method headSync
headSync: ( url: string, parameters: any, headers: any, success: (result: HTTPResponse) => void, failure: (error: any) => void) => string;
Make a sync HEAD request
Parameter url
The url to send the request to
Parameter parameters
Parameters to send with the request
Parameter headers
The headers to set for this request
Parameter success
A callback that is called when the request succeed
Parameter failure
A callback that is called when the request failed
Returns
{string} returns a string that represents the requestId
method options
options: (url: string, parameters: any, headers: any) => Promise<HTTPResponse>;
Make an OPTIONS request
Parameter url
The url to send the request to
Parameter parameters
Parameters to send with the request
Parameter headers
The headers to set for this request
Returns
{Promise} returns a promise that will resolve on success, and reject on failure
method optionsSync
optionsSync: ( url: string, parameters: any, headers: any, success: (result: HTTPResponse) => void, failure: (error: any) => void) => string;
Make an sync OPTIONS request
Parameter url
The url to send the request to
Parameter parameters
Parameters to send with the request
Parameter headers
The headers to set for this request
Parameter success
A callback that is called when the request succeed
Parameter failure
A callback that is called when the request failed
Returns
{string} returns a string that represents the requestId
method patch
patch: (url: string, body: any, headers: any) => Promise<HTTPResponse>;
Make a PATCH request
Parameter url
The url to send the request to
Parameter body
The body of the request
Parameter headers
The headers to set for this request
Returns
{Promise} returns a promise that will resolve on success, and reject on failure
method patchSync
patchSync: ( url: string, body: any, headers: any, success: (result: HTTPResponse) => void, failure: (error: any) => void) => string;
Make a sync PATCH request
Parameter url
The url to send the request to
Parameter body
The body of the request
Parameter headers
The headers to set for this request
Parameter success
A callback that is called when the request succeed
Parameter failure
A callback that is called when the request failed
Returns
{string} returns a string that represents the requestId
method post
post: (url: string, body: any, headers: any) => Promise<HTTPResponse>;
Make a POST request
Parameter url
The url to send the request to
Parameter body
The body of the request
Parameter headers
The headers to set for this request
Returns
{Promise} returns a promise that will resolve on success, and reject on failure
method postSync
postSync: ( url: string, body: any, headers: any, success: (result: HTTPResponse) => void, failure: (error: any) => void) => string;
Make a sync POST request
Parameter url
The url to send the request to
Parameter body
The body of the request
Parameter headers
The headers to set for this request
Parameter success
A callback that is called when the request succeed
Parameter failure
A callback that is called when the request failed
Returns
{string} returns a string that represents the requestId
method put
put: (url: string, body: any, headers: any) => Promise<HTTPResponse>;
Make a PUT request
Parameter url
The url to send the request to
Parameter body
The body of the request
Parameter headers
The headers to set for this request
Returns
{Promise} returns a promise that will resolve on success, and reject on failure
method putSync
putSync: ( url: string, body: any, headers: any, success: (result: HTTPResponse) => void, failure: (error: any) => void) => string;
Make a sync PUT request
Parameter url
The url to send the request to
Parameter body
The body of the request
Parameter headers
The headers to set for this request
Parameter success
A callback that is called when the request succeed
Parameter failure
A callback that is called when the request failed
Returns
{string} returns a string that represents the requestId
method removeCookies
removeCookies: (url: string, cb: () => void) => void;
Remove cookies for given URL.
Parameter url
Parameter cb
method sendRequest
sendRequest: ( url: string, options: { method: | 'get' | 'post' | 'put' | 'patch' | 'head' | 'delete' | 'options' | 'upload' | 'download'; data?: { [index: string]: any }; params?: { [index: string]: string | number }; serializer?: 'json' | 'urlencoded' | 'utf8' | 'multipart' | 'raw'; timeout?: number; headers?: { [index: string]: string }; filePath?: string | string[]; name?: string | string[]; responseType?: 'text' | 'arraybuffer' | 'blob' | 'json'; }) => Promise<HTTPResponse>;
Parameter url
The url to send the request to
Parameter options
options for individual request
Parameter
options.method {string} request method
Parameter
options.data {Object} payload to be send to the server (only applicable on post, put or patch methods)
Parameter
options.params {Object} query params to be appended to the URL (only applicable on get, head, delete, upload or download methods)
Parameter
options.serializer {string} data serializer to be used (only applicable on post, put or patch methods), defaults to global serializer value, see setDataSerializer for supported values
Parameter
options.timeout {number} timeout value for the request in seconds, defaults to global timeout value
Parameter
options.headers {Object} headers object (key value pair), will be merged with global values
Parameter
options.filePath {string} file path(s) to be used during upload and download see uploadFile and downloadFile for detailed information
Parameter
options.name {string} name(s) to be used during upload see uploadFile for detailed information
Parameter
options.responseType {string} response type, defaults to text
Returns
{Promise} returns a promise that will resolve on success, and reject on failure
method sendRequestSync
sendRequestSync: ( url: string, options: { method: | 'get' | 'post' | 'put' | 'patch' | 'head' | 'delete' | 'options' | 'upload' | 'download'; data?: { [index: string]: any }; params?: { [index: string]: string | number }; serializer?: 'json' | 'urlencoded' | 'utf8' | 'multipart'; timeout?: number; headers?: { [index: string]: string }; filePath?: string | string[]; name?: string | string[]; responseType?: 'text' | 'arraybuffer' | 'blob' | 'json'; }, success: (result: HTTPResponse) => void, failure: (error: any) => void) => string;
Parameter url
The url to send the request to
Parameter options
options for individual request
Parameter
options.method {string} request method
Parameter
options.data {Object} payload to be send to the server (only applicable on post, put or patch methods)
Parameter
options.params {Object} query params to be appended to the URL (only applicable on get, head, delete, upload or download methods)
Parameter
options.serializer {string} data serializer to be used (only applicable on post, put or patch methods), defaults to global serializer value, see setDataSerializer for supported values
Parameter
options.timeout {number} timeout value for the request in seconds, defaults to global timeout value
Parameter
options.headers {Object} headers object (key value pair), will be merged with global values
Parameter
options.filePath {string} file path(s) to be used during upload and download see uploadFile and downloadFile for detailed information
Parameter
options.name {string} name(s) to be used during upload see uploadFile for detailed information
Parameter
options.responseType {string} response type, defaults to text
Parameter success
A callback that is called when the request succeed
Parameter failure
A callback that is called when the request failed
Returns
{string} returns a string that represents the requestId
method setCookie
setCookie: (url: string, cookie: string) => void;
Add a custom cookie.
Parameter url
Scope of the cookie
Parameter cookie
RFC compliant cookie string
method setDataSerializer
setDataSerializer: ( serializer: 'urlencoded' | 'json' | 'utf8' | 'multipart' | 'raw') => void;
Set the data serializer which will be used for all future POST, PUT and PATCH requests. Takes a string representing the name of the serializer.
Parameter serializer
The name of the serializer.
See Also
https://github.com/silkimen/cordova-plugin-advanced-http#setdataserializer
method setFollowRedirect
setFollowRedirect: (follow: boolean) => void;
Configure if it should follow redirects automatically.
Parameter follow
Set to false to disable following redirects automatically
method setHeader
setHeader: (host: string, header: string, value: string) => void;
Set a header for all future requests. Takes a hostname, a header and a value.
Parameter host
The hostname to be used for scoping this header
Parameter header
The name of the header
Parameter value
The value of the header
method setRequestTimeout
setRequestTimeout: (timeout: number) => void;
Set global request timeout value in seconds.
Parameter timeout
The timeout in seconds. Default 60
method setServerTrustMode
setServerTrustMode: ( mode: 'default' | 'legacy' | 'nocheck' | 'pinned') => Promise<void>;
Set server trust mode, being one of the following values: default: default SSL trustship and hostname verification handling using system's CA certs; legacy: use legacy default behavior (< 2.0.3), excluding user installed CA certs (only for Android); nocheck: disable SSL certificate checking and hostname verification, trusting all certs (meant to be used only for testing purposes); pinned: trust only provided certificates;
Parameter mode
server trust mode
See Also
https://github.com/silkimen/cordova-plugin-advanced-http#setservertrustmode
method uploadFile
uploadFile: ( url: string, body: any, headers: any, filePath: string | string[], name: string | string[]) => Promise<any>;
Parameter url
The url to send the request to
Parameter body
The body of the request
Parameter headers
The headers to set for this request
Parameter filePath
The local path(s) of the file(s) to upload
Parameter name
The name(s) of the parameter to pass the file(s) along as
Returns
{Promise} returns a FileEntry promise that will resolve on success, and reject on failure
method uploadFileSync
uploadFileSync: ( url: string, body: any, headers: any, filePath: string | string[], name: string | string[], success: (result: any) => void, failure: (error: any) => void) => string;
Parameter url
The url to send the request to
Parameter body
The body of the request
Parameter headers
The headers to set for this request
Parameter filePath
The local path(s) of the file(s) to upload
Parameter name
The name(s) of the parameter to pass the file(s) along as
Parameter success
A callback that is called when the request succeed
Parameter failure
A callback that is called when the request failed
Returns
{string} returns a string that represents the requestId
method useBasicAuth
useBasicAuth: (username: string, password: string) => void;
This sets up all future requests to use Basic HTTP authentication with the given username and password.
Parameter username
Username
Parameter password
Password
Interfaces
interface HTTPResponse
interface HTTPResponse {}
property data
data?: any;
The data that is in the response. This property usually exists when a promise returned by a request method resolves.
property error
error?: string;
Error response from the server. This property usually exists when a promise returned by a request method rejects.
property headers
headers: { [key: string]: string;};
The headers of the response.
property status
status: number;
The HTTP status number of the response or a negative internal error code.
property url
url: string;
The URL of the response. This property will be the final URL obtained after any redirects.
Package Files (1)
Dependencies (1)
Dev Dependencies (0)
No dev dependencies.
Peer Dependencies (2)
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@ionic-native/http
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@ionic-native/http)
- HTML<a href="https://www.jsdocs.io/package/@ionic-native/http"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 2001 ms. - Missing or incorrect documentation? Open an issue for this package.