Core plugins that provide essential functionality like HTTP requests, cookie management, and WebView control, integrated directly into the Capacitor Android runtime.
Native HTTP request handling plugin that provides enhanced networking capabilities with proper cookie management and request/response processing.
/**
* HTTP request handling plugin for enhanced networking
* Provides native HTTP capabilities with cookie support
*/
@CapacitorPlugin(name = "CapacitorHttp")
public class CapacitorHttp extends Plugin {
/**
* Make HTTP request with full configuration options
* Supports all HTTP methods, headers, and request body types
*/
@PluginMethod
public void request(PluginCall call);
/**
* Make GET HTTP request with configuration options
*/
@PluginMethod
public void get(PluginCall call);
/**
* Make POST HTTP request with configuration options
*/
@PluginMethod
public void post(PluginCall call);
/**
* Make PUT HTTP request with configuration options
*/
@PluginMethod
public void put(PluginCall call);
/**
* Make PATCH HTTP request with configuration options
*/
@PluginMethod
public void patch(PluginCall call);
/**
* Make DELETE HTTP request with configuration options
*/
@PluginMethod
public void delete(PluginCall call);
}Request Parameters:
/**
* HTTP request parameters for CapacitorHttp.request()
*/
interface HttpRequestParams {
/** Request URL string */
String url;
/** HTTP method (GET, POST, PUT, DELETE, etc.) */
String method;
/** Request headers as key-value pairs */
JSObject headers;
/** Request body data */
Object data;
/** Data type for request body (json, formData, text, etc.) */
String dataType;
/** Connection timeout in milliseconds */
Integer timeout;
/** Whether to follow redirects */
Boolean followRedirects;
/** Whether to disable SSL certificate validation */
Boolean disableRedirects;
}
/**
* HTTP response format from CapacitorHttp.request()
*/
interface HttpResponse {
/** Response status code */
int status;
/** Response headers as key-value pairs */
JSObject headers;
/** Response data */
Object data;
/** Response URL (may differ from request URL due to redirects) */
String url;
}Usage Examples:
// JavaScript usage that this plugin handles:
// const response = await CapacitorHttp.request({
// url: 'https://api.example.com/data',
// method: 'POST',
// headers: {
// 'Content-Type': 'application/json',
// 'Authorization': 'Bearer token123'
// },
// data: { key: 'value' }
// });
@PluginMethod
public void customHttpRequest(PluginCall call) {
// Example of using CapacitorHttp from another plugin
JSObject requestConfig = new JSObject();
requestConfig.put("url", "https://api.example.com/validate");
requestConfig.put("method", "GET");
JSObject headers = new JSObject();
headers.put("User-Agent", "CapacitorApp/1.0");
requestConfig.put("headers", headers);
// Make request using the HTTP plugin
// Response will be processed by CapacitorHttp.request()
}Cookie management plugin that handles cookie synchronization between the WebView and native HTTP requests, with proper domain and path handling.
/**
* Cookie management plugin for WebView and HTTP synchronization
* Handles cookie storage, retrieval, and synchronization
*/
@CapacitorPlugin(name = "CapacitorCookies")
public class CapacitorCookies extends Plugin {
/**
* Get all cookies for specified URL
* Returns cookies that match the URL's domain and path
*/
@PluginMethod
public void getCookies(PluginCall call);
/**
* Set a cookie with specified options
* Supports all standard cookie attributes
*/
@PluginMethod
public void setCookie(PluginCall call);
/**
* Delete a specific cookie
* Removes cookie by name, domain, and path
*/
@PluginMethod
public void deleteCookie(PluginCall call);
/**
* Clear all cookies for a domain
* Removes all cookies matching the specified domain
*/
@PluginMethod
public void clearCookies(PluginCall call);
/**
* Clear all cookies from storage
* Removes all stored cookies
*/
@PluginMethod
public void clearAllCookies(PluginCall call);
}Cookie Parameters:
/**
* Cookie parameters for CapacitorCookies methods
*/
interface CookieOptions {
/** Cookie name */
String key;
/** Cookie value */
String value;
/** Cookie domain */
String domain;
/** Cookie path */
String path;
/** Expiration date as ISO string or timestamp */
String expires;
/** Whether cookie is HTTP-only */
Boolean httpOnly;
/** Whether cookie requires secure connection */
Boolean secure;
/** SameSite attribute (strict, lax, none) */
String sameSite;
/** URL for cookie context */
String url;
}
/**
* Cookie response format
*/
interface CookieResponse {
/** Array of cookie objects */
JSArray cookies;
}
/**
* Individual cookie object
*/
interface Cookie {
/** Cookie name */
String key;
/** Cookie value */
String value;
/** Cookie domain */
String domain;
/** Cookie path */
String path;
/** Expiration timestamp */
Long expires;
/** HTTP-only flag */
Boolean httpOnly;
/** Secure flag */
Boolean secure;
/** SameSite setting */
String sameSite;
}Usage Examples:
// JavaScript usage examples:
// await CapacitorCookies.setCookie({
// url: 'https://example.com',
// key: 'session',
// value: 'abc123',
// expires: '2024-12-31',
// httpOnly: true
// });
//
// const cookies = await CapacitorCookies.getCookies({
// url: 'https://example.com'
// });
@PluginMethod
public void manageCookies(PluginCall call) {
// Example of cookie management from another plugin
String url = call.getString("url", "");
// Get existing cookies
JSObject getCookiesParams = new JSObject();
getCookiesParams.put("url", url);
// Set a new cookie
JSObject setCookieParams = new JSObject();
setCookieParams.put("url", url);
setCookieParams.put("key", "customCookie");
setCookieParams.put("value", "customValue");
setCookieParams.put("httpOnly", true);
setCookieParams.put("secure", true);
// Cookie operations handled by CapacitorCookies plugin
}WebView management plugin that provides control over the Capacitor WebView, including path configuration and server settings.
/**
* WebView management plugin for Capacitor WebView control
* Provides configuration and path management
*/
@CapacitorPlugin(name = "WebView")
public class WebView extends Plugin {
/**
* Set the server asset path for loading local files
* Configures how local assets are served to the WebView
*/
@PluginMethod
public void setServerAssetPath(PluginCall call);
/**
* Set the server base path
* Configures the base path for asset serving
*/
@PluginMethod
public void setServerBasePath(PluginCall call);
/**
* Get the current server base path
* Returns the base path used for serving assets
*/
@PluginMethod
public void getServerBasePath(PluginCall call);
/**
* Persist the server base path to storage
* Saves the current base path for future app launches
*/
@PluginMethod
public void persistServerBasePath(PluginCall call);
}WebView Parameters:
/**
* WebView configuration parameters
*/
interface WebViewConfig {
/** Asset path for local file serving */
String path;
/** Base path for server operations */
String basePath;
/** File source URL to convert */
String url;
/** User agent string */
String userAgent;
}
/**
* WebView response formats
*/
interface WebViewResponse {
/** Current or updated path */
String path;
/** Converted URL for file sources */
String url;
/** Current user agent */
String userAgent;
}Usage Examples:
// JavaScript usage examples:
// await WebView.setServerAssetPath({ path: '/custom/assets' });
// const basePath = await WebView.getServerBasePath();
// const fileUrl = await WebView.convertFileSrc({ url: 'file:///path/to/file.jpg' });
@PluginMethod
public void configureWebView(PluginCall call) {
// Example of WebView configuration from another plugin
String customPath = call.getString("customPath");
if (customPath != null) {
// Configure asset path
JSObject pathConfig = new JSObject();
pathConfig.put("path", customPath);
// Set custom user agent
JSObject agentConfig = new JSObject();
agentConfig.put("userAgent", "CustomApp/1.0 (Android)");
// WebView configuration handled by WebView plugin
}
call.resolve();
}Utility classes and interfaces that support the built-in plugins and their integration with the Capacitor runtime.
/**
* HTTP utility classes for CapacitorHttp plugin
*/
public class HttpRequestHandler {
/**
* Handle HTTP request processing
* @param request - HTTP request configuration
* @returns HTTP response data
*/
public static HttpResponse processRequest(HttpRequestConfig request);
}
/**
* Cookie manager for CapacitorCookies plugin
*/
public class CapacitorCookieManager {
/**
* Get cookie manager instance
* @param context - Android context
* @returns Cookie manager for operations
*/
public static CapacitorCookieManager getInstance(Context context);
/**
* Synchronize cookies between WebView and HTTP client
*/
public void syncCookies(String url);
}
/**
* Asset utilities for WebView plugin
*/
public class AssetUtil {
/**
* Get asset input stream
* @param context - Android context
* @param assetPath - Path to asset file
* @returns InputStream for asset or null if not found
*/
public static InputStream getAssetStream(Context context, String assetPath);
/**
* Check if asset exists
* @param context - Android context
* @param assetPath - Path to check
* @returns Boolean indicating if asset exists
*/
public static boolean assetExists(Context context, String assetPath);
}
/**
* MIME type utilities
*/
public class MimeType {
/**
* Get MIME type from file extension
* @param extension - File extension (with or without dot)
* @returns MIME type string or application/octet-stream
*/
public static String fromExtension(String extension);
/**
* Get file extension from MIME type
* @param mimeType - MIME type string
* @returns File extension or empty string
*/
public static String getExtension(String mimeType);
}Usage Examples:
// Example of creating a custom plugin that works with built-in plugins
@CapacitorPlugin(name = "CustomNetworking")
public class CustomNetworkingPlugin extends Plugin {
@PluginMethod
public void makeAuthenticatedRequest(PluginCall call) {
String url = call.getString("url");
String token = call.getString("token");
// Use CapacitorCookies to get existing cookies
JSObject cookieParams = new JSObject();
cookieParams.put("url", url);
// Use CapacitorHttp to make request with authentication
JSObject requestParams = new JSObject();
requestParams.put("url", url);
requestParams.put("method", "GET");
JSObject headers = new JSObject();
headers.put("Authorization", "Bearer " + token);
requestParams.put("headers", headers);
// Request will be processed by the built-in HTTP plugin
call.resolve();
}
@PluginMethod
public void loadLocalAsset(PluginCall call) {
String assetPath = call.getString("path");
// Check if asset exists using WebView utilities
if (AssetUtil.assetExists(getContext(), assetPath)) {
// Convert to WebView-compatible URL
JSObject convertParams = new JSObject();
convertParams.put("url", "file:///android_asset/" + assetPath);
// URL conversion handled by WebView plugin
JSObject result = new JSObject();
result.put("available", true);
result.put("mimeType", MimeType.fromExtension(FileUtils.getFileExtension(assetPath)));
call.resolve(result);
} else {
call.reject("Asset not found");
}
}
}