Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/capacitor-community/http
Community plugin for native HTTP
https://github.com/capacitor-community/http
capacitor http
Last synced: about 1 month ago
JSON representation
Community plugin for native HTTP
- Host: GitHub
- URL: https://github.com/capacitor-community/http
- Owner: capacitor-community
- License: mit
- Archived: true
- Created: 2020-05-27T20:15:35.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-09-14T15:31:11.000Z (about 2 years ago)
- Last Synced: 2024-04-28T09:31:20.766Z (8 months ago)
- Topics: capacitor, http
- Language: Java
- Homepage:
- Size: 11.9 MB
- Stars: 207
- Watchers: 14
- Forks: 135
- Open Issues: 87
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
- awesome-capacitorjs - @capacitor-community/http - Community plugin for native HTTP. (Plugins / Community Plugins)
- awesome-capacitor - Http - A native HTTP plugin for CORS-free requests and file transfers. (Community plugins)
README
HTTP
@capacitor-community/http
Capacitor community plugin for native HTTP requests, file download/uploads, and cookie management.## Maintainers
| Maintainer | GitHub | Social |
| ------------ | --------------------------------------------- | ----------------------------------------------- |
| Max Lynch | [mlynch](https://github.com/mlynch) | [@maxlynch](https://twitter.com/maxlynch) |
| Thomas Vidas | [thomasvidas](https://github.com/thomasvidas) | [@thomasvidas](https://twitter.com/thomasvidas) |## Installation
```bash
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](https://github.com/ionic-team/capacitor/issues/5145). 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](https://github.com/ionic-team/capacitor-plugins). 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`.
```bash
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](https://developer.android.com/training/articles/security-config) article.## Usage
To use the plugin while fully supporting the web version, import and use it like this:
```typescript
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.
```xml
WKAppBoundDomainswww.mydomain.com
api.mydomain.com
www.myothercooldomain.com```
## Contributors β¨
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/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](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!