Skip to content

Instantly share code, notes, and snippets.

/HTTP.ts Secret

Created May 1, 2017 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/2f07a811beb0b92de84b70c8b606f312 to your computer and use it in GitHub Desktop.
Save anonymous/2f07a811beb0b92de84b70c8b606f312 to your computer and use it in GitHub Desktop.
HTTP Ionic 3
/**
* This returns an object representing a basic HTTP Authorization header of the form.
* @param username {string} Username
* @param password {string} Password
* @returns {Object} an object representing a basic HTTP Authorization header of the form {'Authorization': 'Basic base64encodedusernameandpassword'}
*/
getBasicAuthHeader(username: string, password: string): {
Authorization: string;
};
/**
* This sets up all future requests to use Basic HTTP authentication with the given username and password.
* @param username {string} Username
* @param password {string} Password
*/
useBasicAuth(username: string, password: string): void;
/**
* Set a header for all future requests. Takes a header and a value.
* @param header {string} The name of the header
* @param value {string} The value of the header
*/
setHeader(header: string, value: string): void;
/**
* Enable or disable SSL Pinning. This defaults to false.
*
* To use SSL pinning you must include at least one .cer SSL certificate in your app project. You can pin to your server certificate or to one of the issuing CA certificates. For ios include your certificate in the root level of your bundle (just add the .cer file to your project/target at the root level). For android include your certificate in your project's platforms/android/assets folder. In both cases all .cer files found will be loaded automatically. If you only have a .pem certificate see this stackoverflow answer. You want to convert it to a DER encoded certificate with a .cer extension.
*
* As an alternative, you can store your .cer files in the www/certificates folder.
* @param enable {boolean} Set to true to enable
* @returns {Promise<void>} returns a promise that will resolve on success, and reject on failure
*/
enableSSLPinning(enable: boolean): Promise<void>;
/**
* Accept all SSL certificates. Or disabled accepting all certificates. Defaults to false.
* @param accept {boolean} Set to true to accept
* @returns {Promise<void>} returns a promise that will resolve on success, and reject on failure
*/
acceptAllCerts(accept: boolean): Promise<void>;
/**
* Whether or not to validate the domain name in the certificate. This defaults to true.
* @param validate {boolean} Set to true to validate
* @returns {Promise<void>} returns a promise that will resolve on success, and reject on failure
*/
validateDomainName(validate: boolean): Promise<void>;
/**
* Make a POST request
* @param url {string} The url to send the request to
* @param body {Object} The body of the request
* @param headers {Object} The headers to set for this request
* @returns {Promise<HTTPResponse>} returns a promise that resolve on success, and reject on failure
*/
post(url: string, body: any, headers: any): Promise<HTTPResponse>;
/**
*
* @param url {string} The url to send the request to
* @param parameters {Object} Parameters to send with the request
* @param headers {Object} The headers to set for this request
* @returns {Promise<HTTPResponse>} returns a promise that resolve on success, and reject on failure
*/
get(url: string, parameters: any, headers: any): Promise<HTTPResponse>;
/**
*
* @param url {string} The url to send the request to
* @param body {Object} The body of the request
* @param headers {Object} The headers to set for this request
* @param filePath {string} The local path of the file to upload
* @param name {string} The name of the parameter to pass the file along as
* @returns {Promise<HTTPResponse>} returns a promise that resolve on success, and reject on failure
*/
uploadFile(url: string, body: any, headers: any, filePath: string, name: string): Promise<HTTPResponse>;
/**
*
* @param url {string} The url to send the request to
* @param body {Object} The body of the request
* @param headers {Object} The headers to set for this request
* @param filePath {string} The path to donwload the file to, including the file name.
* @returns {Promise<HTTPResponse>} returns a promise that resolve on success, and reject on failure
*/
downloadFile(url: string, body: any, headers: any, filePath: string): Promise<HTTPResponse>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment