capacitor-community / http

Licence: MIT license
Community plugin for native HTTP

Programming Languages

java
68154 projects - #9 most used programming language
typescript
32286 projects
swift
15916 projects
javascript
184084 projects - #8 most used programming language
ruby
36898 projects - #4 most used programming language
objective c
16641 projects - #2 most used programming language

Projects that are alternatives of or similar to http

v-cupertino
A Vue 3 Wrapper for Cupertino Pane Library
Stars: ✭ 17 (-91.75%)
Mutual labels:  capacitor
cordova-plugin-apkupdater
This plugin allows your Android app to download and install compressed updates without the Google Play Store.
Stars: ✭ 46 (-77.67%)
Mutual labels:  capacitor
Nativescript
NativeScript empowers you to access native platform APIs from JavaScript directly. Angular, Capacitor, Ionic, React, Svelte, Vue and you name it compatible.
Stars: ✭ 20,730 (+9963.11%)
Mutual labels:  capacitor
capacitor-vue-ionicv4-app
sample app using capacitor vuejs and ionicv4 components
Stars: ✭ 70 (-66.02%)
Mutual labels:  capacitor
XREngine
Immersive infrastructure for everyone. Everything you need to build and deploy scalable realtime 3D social apps and more. 🤖 🚀 👓 🚀 🕹️ 🚀 🧑🏿‍🚀
Stars: ✭ 423 (+105.34%)
Mutual labels:  capacitor
capacitor-background-task
⚡️ Capacitor plugin for running background tasks.
Stars: ✭ 27 (-86.89%)
Mutual labels:  capacitor
appcenter-sdk-capacitor
Capacitor Plugin for Microsoft's Visual Studio App Center SDK.
Stars: ✭ 22 (-89.32%)
Mutual labels:  capacitor
capacitor-rate-app
Let users rate your app using native review app dialog for both Android and iOS.
Stars: ✭ 88 (-57.28%)
Mutual labels:  capacitor
tutorial-photo-gallery-vue
Photo Gallery Tutorial: Ionic Vue and Capacitor
Stars: ✭ 33 (-83.98%)
Mutual labels:  capacitor
app-icon
Capacitor plugin for managing an app's icon. The main feature being that you can programmatically change the app icon.
Stars: ✭ 28 (-86.41%)
Mutual labels:  capacitor
ionic-firebase-image-upload
Building an Ionic App with Protected/Private Content. This app shows how to use Firebase Storage from an Ionic Angular app both with public and private content.
Stars: ✭ 19 (-90.78%)
Mutual labels:  capacitor
text-to-speech
⚡️ Capacitor plugin for synthesizing speech from text.
Stars: ✭ 50 (-75.73%)
Mutual labels:  capacitor
blobile
Blases Loaded - Unofficial Live Blaseball Game Viewer for iOS, Android, and Web
Stars: ✭ 16 (-92.23%)
Mutual labels:  capacitor
native-xr-for-web
Add iOS and Android build with AR capabilities to your website or web-based app.
Stars: ✭ 27 (-86.89%)
Mutual labels:  capacitor
Capacitor
Build cross-platform Native Progressive Web Apps for iOS, Android, and the Web ⚡️
Stars: ✭ 6,598 (+3102.91%)
Mutual labels:  capacitor
ionic-vue-mobile-template-03
Hybrid app template built with vue, ionic and capacitor.
Stars: ✭ 62 (-69.9%)
Mutual labels:  capacitor
firebase-crashlytics
⚡️ Capacitor plugin for Firebase Crashlytics.
Stars: ✭ 63 (-69.42%)
Mutual labels:  capacitor
capacitor-site
Capacitor website
Stars: ✭ 0 (-100%)
Mutual labels:  capacitor
Ionic Framework
A powerful cross-platform UI toolkit for building native-quality iOS, Android, and Progressive Web Apps with HTML, CSS, and JavaScript.
Stars: ✭ 45,802 (+22133.98%)
Mutual labels:  capacitor
ionic-level
iOS level app clone made with Angular, Ionic & Capacitor.
Stars: ✭ 19 (-90.78%)
Mutual labels:  capacitor


HTTP

@capacitor-community/http

Capacitor community plugin for native HTTP requests, file download/uploads, and cookie management.


Maintainers

Maintainer GitHub Social
Max Lynch mlynch @maxlynch
Thomas Vidas thomasvidas @thomasvidas

Installation

npm install @capacitor-community/http
npx cap sync

Maintence Mode

The next iteration of this plugin will be an official plugin bundled with Capacitor 4.x. In order for a smooth transition, this repo will be in maintence mode with no new features added until the plugin moves to the main Capacitor Plugins repo. In the meantime, if there are critical security bug fixes required, they will still be made to this plugin as a patch release.

Capacitor 2.x

For Capacitor 2.x projects, you will need to install a version less than 1.0.0. You can do that by specifying the version in your package.json or installing like this. The latest 2.x compatible version is 0.3.1.

npm install @capacitor-community/[email protected]

Configuration

In most cases no configuration is required for this plugin. If the Android application connects with use the self-signed certificates or without encryption, see Network security configuration article.

Usage

To use the plugin while fully supporting the web version, import and use it like this:

import { Http } from '@capacitor-community/http';

// Example of a GET request
const doGet = () => {
  const options = {
    url: 'https://example.com/my/api',
    headers: { 'X-Fake-Header': 'Max was here' },
    params: { size: 'XL' },
  };

  const response: HttpResponse = await Http.get(options);

  // or...
  // const response = await Http.request({ ...options, method: 'GET' })
};

// Example of a POST request. Note: data
// can be passed as a raw JS Object (must be JSON serializable)
const doPost = () => {
  const options = {
    url: 'https://example.com/my/api',
    headers: { 'X-Fake-Header': 'Thomas was here' },
    data: { foo: 'bar', cool: true },
  };

  const response: HttpResponse = await Http.post(options);

  // or...
  // const response = await Http.request({ ...options, method: 'POST' })
};

const setCookie = async () => {
  const options = {
    url: 'http://example.com',
    key: 'language',
    value: 'en',
  };

  await Http.setCookie(options);
};

const deleteCookie = async () => {
  const options = {
    url: 'http://example.com',
    key: 'language',
  };

  await Http.deleteCookie(options);
};

const clearCookies = async () => {
  await Http.clearCookies({ url: 'http://example.com' });
};

const getCookies = async () => {
  const cookies: HttpCookie[] = await Http.getCookies({
    url: 'http://example.com',
  });
};

const downloadFile = async () => {
  const options = {
    url: 'https://example.com/path/to/download.pdf',
    filePath: 'document.pdf',
    fileDirectory: Directory.Downloads,
    // Optional
    method: 'GET',
  };

  // Writes to local filesystem
  const response: HttpDownloadFileResult = await Http.downloadFile(options);

  // Then read the file
  if (response.path) {
    const read = await Filesystem.readFile({
      path: 'download.pdf',
      directory: Directory.Downloads,
    });
  }
};

const uploadFile = async () => {
  const options = {
    url: 'https://example.com/path/to/upload.pdf',
    name: 'myFile',
    filePath: 'document.pdf',
    fileDirectory: FilesystemDirectory.Downloads,
  };

  const response: HttpUploadFileResult = await Http.uploadFile();
};

API Reference

You can view the API Reference generated by TypeDoc here: https://capacitor-community.github.io/http/docs/classes/web.httpweb.html

Third Party Cookies on iOS

As of iOS 14, you cannot use 3rd party cookies by default. There is an open issue on the Capacitor Core repo on properly patching in cookies on iOS. For now, you must specify a domain of for the cookie you are saving to properly save and send them via requests. You can also add the following lines to your Info.plist file to get better support for cookies on iOS. You can add up to 10 domains.

<key>WKAppBoundDomains</key>
<array>
    <string>www.mydomain.com</string>
    <string>api.mydomain.com</string>
    <string>www.myothercooldomain.com</string>
</array>

Contributors

Thanks goes to these wonderful people (emoji key):


Daniel Sogl

📖

Priyank Patel

💻

Max Lynch

💻

Falk Schieber

👀

Andy Sousa

💻

Thomas Vidas

💻 🚧

Emily Curry

💻

graefenhain

💻

Lee Houghton

🐛

Felix Schwarzmeier

💻

Kamil Jakubus

💻

Joe Flateau

🐛

Frank608

🐛

Joel Nieto

🐛

ultimate-tester

💻

Adrian Sanchez

🐛

milanc

💻

herecoulbeyourname

💻

Landschaft

💻

stonewoodman

🐛

Héctor Cruz

🐛

Patrick Bußmann

💻

Jesper Bjerke

🐛

This project follows the all-contributors specification. Contributions of any kind welcome!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].