React Native HTTP

raw JSON →
0.0.3 verified Sat Apr 25 auth: no javascript

React Native HTTP is a lightweight HTTP service wrapper for React Native applications, designed to simplify API interactions with built-in JWT token handling. Version 0.0.3 is the latest stable release, but the package appears to be in early development with sparse documentation. It provides an abstract base class HTTPService that supports GET, POST, PUT, DELETE methods with automatic token management (Authorization header, Bearer prefix, storage key). Key differentiators: minimal overhead, token lifecycle handled internally, supports per-request authorization skipping. However, it lacks TypeScript definitions, testing, and a clear roadmap; alternatives like axios or react-native-netinfo are more mature. The project is currently in maintenance mode with infrequent updates.

error TypeError: _reactNativeHttp.default is not a function
cause Default import used but package only exports named exports.
fix
Use named import: import { HTTPService } from 'react-native-http'
error Cannot find module 'react-native-http'
cause Package is not installed or is in development mode.
fix
Run npm install react-native-http --save
error undefined is not an object (evaluating 'this.jwtService.setToken')
cause JWT token handling requires that the underlying HTTPService sets jwtService before calling methods that expect token.
fix
Ensure the HTTPService constructor is called with a baseURL and that the storageTokenPrefix (default: react_native_http_jwt_token) is set in AsyncStorage.
gotcha The package relies on react-native AsyncStorage for token storage; if AsyncStorage is removed in newer RN versions, token handling will fail.
fix Consider switching to @react-native-async-storage/async-storage as a polyfill, or implement custom token storage.
gotcha The skipAuthorization option must be passed as the third parameter to methods (e.g., this.get(path, null, {skipAuthorization: true})). Omitting it or placing it incorrectly will not skip authorization.
fix Always pass options as the third argument; for GET and DELETE, the second argument (body) should be null if not needed.
breaking The package does not handle network errors gracefully; HTTP errors may reject the promise without detailed status codes.
fix Wrap calls in try-catch or add .catch handlers to inspect error objects.
npm install react-native-http
yarn add react-native-http
pnpm add react-native-http

Creates a custom API class extending HTTPService with GET and POST methods, then instantiates it and calls getUsers.

import { HTTPService } from 'react-native-http';

class MyAPI extends HTTPService {
  getUsers() {
    return this.get('users/');
  }

  createUser(data) {
    return this.post('users/', data);
  }
}

const api = new MyAPI('https://api.example.com');
api.getUsers().then(response => console.log(response)).catch(error => console.error(error));