@pluskode/client-expo
v0.1.1
Published
Pluskode Client SDK for Expo - Optimized for Expo managed workflow with HTTPS/WSS support
Maintainers
Readme
Pluskode Expo Client SDK
Expo-optimized client SDK for Pluskode Backend Framework.
Status
✅ Ready - Optimized for Expo managed workflow
Features
- ✅ HTTP client (HTTPS required in production)
- ✅ WebSocket client (WSS required in production)
- ✅ SSE client
- ✅ gRPC client (via gRPC-Web)
- ✅ MQTT client (over WebSocket)
- ✅ Binary stream support (via WebSocket binary frames)
- ✅ Automatic HTTPS/WSS enforcement
- ✅ App Store/Play Store compliant
- ✅ Pure JavaScript/TypeScript (no native modules)
Installation
npm install @pluskode/client-expo
# or
yarn add @pluskode/client-expoUsage
Basic Setup
import { PluskodeExpoClient } from '@pluskode/client-expo';
// Production (HTTPS required)
const client = new PluskodeExpoClient({
baseURL: 'https://api.example.com',
timeout: 30000,
retries: 3
});
// Development (localhost HTTP allowed)
const devClient = new PluskodeExpoClient({
baseURL: 'http://localhost:3000',
enforceSecure: false // Allow HTTP for localhost
});HTTP Requests
// GET request
const users = await client.get('/api/users');
// POST request
const newUser = await client.post('/api/users', {
name: 'John',
email: '[email protected]'
});
// PUT, PATCH, DELETE
await client.put('/api/users/123', { name: 'Jane' });
await client.patch('/api/users/123', { email: '[email protected]' });
await client.delete('/api/users/123');WebSocket
// Subscribe to channel (uses WSS automatically)
const unsubscribe = client.subscribe('chat/room1', (data) => {
console.log('Message:', data);
});
// Send message
client.send('chat/room1', { text: 'Hello!' });
// Unsubscribe
unsubscribe();Server-Sent Events (SSE)
const unsubscribe = client.subscribeSSE('/events/stream', (event) => {
console.log('Event:', event.event, 'Data:', event.data);
});
// Close
unsubscribe();gRPC (via gRPC-Web)
const user = await client.rpc(
'UserService',
'GetUser',
{ id: '123' }
);MQTT (over WebSocket)
// Subscribe
const unsubscribe = client.subscribeMQTT(
'sensors/temperature',
(topic, message, qos) => {
console.log(`${topic}: ${message} (QoS: ${qos})`);
},
{ qos: 1 }
);
// Publish
await client.publishMQTT(
'sensors/temperature',
'25.5',
{ qos: 1, retain: false }
);Expo Example
import React, { useEffect, useState } from 'react';
import { View, Text, FlatList } from 'react-native';
import { PluskodeExpoClient } from '@pluskode/client-expo';
const client = new PluskodeExpoClient({
baseURL: __DEV__ ? 'http://localhost:3000' : 'https://api.example.com'
});
export function UsersScreen() {
const [users, setUsers] = useState([]);
const [messages, setMessages] = useState([]);
useEffect(() => {
// Load users
client.get('/api/users')
.then(res => setUsers(res.data))
.catch(err => console.error(err));
// Subscribe to chat
const unsubscribe = client.subscribe('chat/room1', (data) => {
setMessages(prev => [...prev, data]);
});
return () => unsubscribe();
}, []);
return (
<View>
<FlatList
data={users}
renderItem={({ item }) => <Text>{item.name}</Text>}
/>
<FlatList
data={messages}
renderItem={({ item }) => <Text>{item.text}</Text>}
/>
</View>
);
}Security & Compliance
HTTPS/WSS Enforcement
- Production: HTTPS/WSS is automatically enforced
- Development: HTTP/WS allowed only for localhost
- App Store/Play Store: Fully compliant
Why HTTPS/WSS?
- App Store Requirements: iOS requires HTTPS for network requests
- Play Store Requirements: Android requires secure connections
- Security: Protects data in transit
- Expo Managed Workflow: No native modules, pure JS/TS
Differences from React Native Client
| Feature | Expo Client | React Native Client | |---------|-------------|---------------------| | Native Modules | ❌ Not supported | ✅ Can use native modules | | HTTPS Enforcement | ✅ Automatic | ⚠️ Manual | | Managed Workflow | ✅ Optimized | ⚠️ May require custom native code | | App Store Ready | ✅ Yes | ⚠️ Depends on setup |
Limitations
Since Expo managed workflow doesn't support custom native modules:
- gRPC: Uses gRPC-Web (via HTTP/HTTPS) instead of native gRPC
- MQTT: Uses MQTT over WebSocket instead of native MQTT
- Binary Streams: Uses WebSocket binary frames instead of raw TCP
These limitations are acceptable for most use cases and ensure App Store/Play Store compliance.
Requirements
- Expo SDK 45.0+
- React Native 0.60+
- TypeScript 5.0+ (optional)
License
MIT
Note: This client is optimized for Expo managed workflow. For bare React Native projects, use @pluskode/client-react-native instead.
