@blackbox-vision/react-native-http-client
v0.0.1
Published
HTTP Client module
Downloads
2
Readme
RN Http Client
This package let us use Axios in a simpler way to handle requests.
Install
You can install this library via NPM or YARN.
NPM
npm i @blackbox-vision/react-native-http-client
YARN
yarn add @blackbox-vision/react-native-http-client
Use case
This library let us handle requests in a simpler way.
Usage
- Create a
http-client.ts
and initialize yourHttpClient
:
// utils/http-client.ts
import Env from "react-native-config";
import { HttpClient } from "@blackbox-vision/react-native-http-client";
import {
YourCustomInterceptor,
ResponseToCamelCase,
} from "./custom-interceptors";
HttpClient.setTimeout(45000);
HttpClient.setBaseURL(Env.BASE_URL);
HttpClient.setHeaders({
"Content-Type": "application/json",
});
HttpClient.setRequestInterceptors(YourCustomInterceptor);
HttpClient.setResponseInterceptors(ResponseToCamelCase);
export default HttpClient;
- Invoke in your service and perform requests:
// services/user.ts
import HttpClient from "utils/http-client";
export const getAll = async (): Promise<User[]> => {
return await HttpClient.get<User[]>(`/users`);
};
Issues
Please, open an issue following one of the issues templates. We will do our best to fix them.
Contributing
If you want to contribute to this project see contributing for more information.
License
Distributed under the MIT license. See LICENSE for more information.