Registry / testing / react-native-rest-client

react-native-rest-client

JSON →
library0.1.1jsnpmunverified

A simple REST client library for React Native applications that provides a base class for creating custom API clients. Version 0.1.1 is the latest stable release, but the package appears to be in early development with no recent updates. It simplifies RESTful calls by offering methods like GET, POST, PUT, PATCH, and DELETE, and supports custom headers, simulated delays for development, and returns Promises. Compared to alternatives like axios or fetch, it is minimal and tightly coupled to React Native, but lacks advanced features like interceptors, cancellation, or request/response transformations.

npm install react-native-rest-client
INSTALL
IMPORT
SIG · REACT-NATIVE-REST-
R
react-native-rest-client
testingjavascriptv0.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

RestClient
import RestClient from 'react-native-rest-client';
import { RestClient } from 'react-native-rest-client';
Default export only. Named import will be undefined.
default
const RestClient = require('react-native-rest-client').default;
const RestClient = require('react-native-rest-client');
CommonJS requires .default due to ESM default export.
YourRestApi
class YourRestApi extends RestClient { ... }
class YourRestApi extends RestClient.default { ... }
Extend the class directly after import, not via .default.

Creates a GitHub API client by extending RestClient, with authentication token and simulated delay in development mode.

import RestClient from 'react-native-rest-client'; export default class GitHubApi extends RestClient { constructor(token) { super('https://api.github.com', { headers: { Authorization: `token ${token}` }, devMode: __DEV__, simulatedDelay: 1000 }); } getRepo(owner, repo) { return this.GET(`/repos/${owner}/${repo}`).then(res => res.data); } } const api = new GitHubApi(process.env.GITHUB_TOKEN ?? ''); api.getRepo('facebook', 'react-native').then(data => { console.log(data); }).catch(err => { console.error(err); });
Debug
Known issues
gotchaThe library does not support request cancellation or timeout configuration, which may lead to unresolved promises if network requests hang.
fix
Implement your own timeout wrapper or switch to a more feature-rich HTTP client like axios.
affects: >=0.0.0
gotchaAll HTTP methods (GET, POST, etc.) return the full fetch response, not the parsed JSON body. You must manually extract data (e.g., response.data).
fix
Chain .then(response => response.data) or use a custom wrapper.
affects: >=0.0.0
gotchaThe simulatedDelay option only works if devMode is set to true and __DEV__ is defined. In production, the delay is ignored even if devMode is true.
fix
Ensure __DEV__ is globally defined as a boolean during development.
affects: >=0.0.0
gotchaThe library uses fetch internally, which is only available in React Native. It will not work in plain Node.js or browsers without polyfill.
fix
Use a fetch polyfill or switch to a universal HTTP client if targeting multiple environments.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: RestClient is not a constructor
Using named import { RestClient } instead of default import.
fix
Change to 'import RestClient from 'react-native-rest-client';'
undefined is not an object (evaluating 'this.GET')
Calling GET, POST, etc. on a wrong context (e.g., not bound to the instance).
fix
Ensure methods are called on the instance: const api = new YourRestApi(); api.GET(...);
Cannot read property 'then' of undefined
Omitting return statement inside a custom method that calls this.GET/POST.
fix
Add 'return' before this.GET() or this.POST() in your method.
Upgrade
Version history
0.1.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
react-native-rest-client — npm install react-native-rest-client · libregistry