Skip to content

Fix Issue 123 #124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Changelog

## [Unreleased]
Cancel http request. This functionality is available using the available axios instance as described in the axios instance section of the table of contents.

## [1.0.3] - 2022-01-xx

### Added
Add changelog file

### Fixed
Give the possibility to clean list of queries added in the directory.
60 changes: 58 additions & 2 deletions docs/readme-fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,45 @@
![React](https://img.shields.io/badge/react-%2320232a.svg?style=for-the-badge&logo=react&logoColor=%2361DAFB)
![React Native](https://img.shields.io/badge/react_native-%2320232a.svg?style=for-the-badge&logo=react&logoColor=%2361DAFB)

## Table of Contents
- [Contexte](#contexte)
- [Fonctionnalités](#fonctionnalit-s)
- [Installation](#installation)
- [Toutes les configurations](#toutes-les-configurations)
* [Initialisation de la librairie](#initialisation-de-la-librairie)
+ [L'application peut être initialisée de 2 manières :](#l-application-peut--tre-initialis-e-de-2-mani-res--)
* [Utilisation des deux hooks](#utilisation-des-deux-hooks)
+ [Hooks sans préchargement](#hooks-sans-pr-chargement)
- [Autre exemple :](#autre-exemple--)
- [Exemple de gestion d'erreur](#exemple-de-gestion-d-erreur)
+ [Hook préchargé](#hook-pr-charg-)
* [Hook avec paramètre](#hook-avec-param-tre)
* [Instances Axios](#instances-axios)
* [Liste des services](#liste-des-services)
+ [Rh2DirectoryService](#rh2directoryservice)
+ [Rh2ConfigService](#rh2configservice)
+ [Rh2AxiosConfigService](#rh2axiosconfigservice)
* [Liste des models Rh2](#liste-des-models-rh2)
+ [Paramètre pour pour les requêtes non pré-chargée](#param-tre-pour-pour-les-requ-tes-non-pr--charg-e)
- [Rh2EffectAxiosConfigHandler](#rh2effectaxiosconfighandler)
- [Rh2EffectData](#rh2effectdata)
+ [AxiosConfig](#axiosconfig)
+ [FetchApi](#fetchapi)
- [ResponseFetchApi](#responsefetchapi)
- [ErreurFetchApi](#erreurfetchapi)
+ [Configuration générale](#configuration-g-n-rale)
- [Rh2InitializationParameter](#rh2initializationparameter)
- [AxiosRequestConfigExtended](#axiosrequestconfigextended)
+ [Rh2InitializationParameter](#rh2initializationparameter-1)
+ [AxiosRequestConfigExtended](#axiosrequestconfigextended-1)
- [Roadmap](#roadmap)

## Contexte

Cette librairie React utilisant les hooks customisés a pour but de faciliter l'utilisateur dans sa manipulation des requêtes HTTP. Il doit simplement configurer la requête qui sera exécutée par Axios, ainsi que le moment du déclenchement.Il est possible d’ajouter des paramètres supplémentaires pour des besoins de l’application cliente. Par exemple, demander qu’une requête soit exécutée seulement une fois via notre système d’historisation; la configuration des traitements à effectuer en cas d’erreurs de requête. Les utilisateurs de redux pourront trouver leur bonheur pour dispatch le résultat de la requête revenue avec succès ou non, celle-ci pourra également être précédée d’un traitement ou non.
Cette librairie React utilisant les hooks customisés a pour but de faciliter l'utilisateur dans sa manipulation des requêtes HTTP. Il doit simplement configurer la requête qui sera exécutée par Axios, ainsi que le moment du déclenchement.Il est possible d’ajouter des paramètres supplémentaires pour des besoins de l’application cliente.
Par exemple :
- Demander qu’une requête soit exécutée seulement une fois via notre système d’historisation; la configuration des traitements à effectuer en cas d’erreurs de requête.
- Les utilisateurs de redux pourront trouver leur bonheur pour dispatch le résultat de la requête revenue avec succès ou non, celle-ci pourra également être précédée d’un traitement ou non.

## Fonctionnalités
- Tout ce que Axios peut faire
Expand Down Expand Up @@ -344,6 +380,22 @@ rh2AxiosConfigService.addAuthToConfigAxios(GOOGLE, {

### Liste des services

#### Rh2DirectoryService

Initialise l’application :

- Gestion des requêtes mise en mémoire pour éviter quelles soient de nouveau exécutées

| Méthode | type | Description |
| ------------------------------------------------------------ | ---------------------- | --------------------------------------------- |
| hasConfigQueryParameter(url: string, method: MethodRnhrh, params?: ParamRnhnh) | boolean | Vérifier la présence de la configuration |
| hasConfigQueryParameterByConfigQueryParameter(parameter: ConfigQueryParameter) | boolean | Vérifier la présence de la configuration |
| addConfigQueryParameter(configTmp: ConfigQueryParameter) | void | Ajouter une configuration à l'annuaire |
| getConfigQueryParameters() | ConfigQueryParameter[] | Récupérer la liste des configurations |
| getConfigQueryParameter(url: string, method: MethodRnhrh, params?: ParamRnhnh) | ConfigQueryParameter | Récupérer une configuration spécifique |
| removeQueryDirectory(axiosRequestConfig: AxiosRequestConfig) | void | Supprimer une configuration précise |
| removeAllQueryDirectory() | void | Supprimer toutes les configuration en mémoire |

#### Rh2ConfigService

Initialise l’application :
Expand Down Expand Up @@ -400,7 +452,7 @@ export interface Rh2EffectAxiosConfigHandler {

<b>axiosRequestConfig</b> Configuration Axios.

<b>addToDirectory</b> S'utilise si l'on veut exécuter une seule fois la requête durant l'utilisation de l'application. Si true, la valeur pourra être mise à jour avec le service <b>QueryStorageService</b> pour être réinitialisée.
<b>addToDirectory</b> S'utilise si l'on veut exécuter une seule fois la requête durant l'utilisation de l'application. Si true, la valeur pourra être mise à jour avec le service <b>Rh2DirectoryService</b> pour être réinitialisée.

| Attention : La condition pour filtrer les requêtes s'appuie sur l'url, le type de méthode et la propriété params. |
| ------------------------------------------------------------ |
Expand Down Expand Up @@ -584,3 +636,7 @@ const initSettings: Rh2InitializationParameter = {

- Modifier une instance Axios pour prendre en compte de nouveaux éléments (Ex : Mise à jour du paramètre «auth» de Axios)
- Gérer l'annulation des requêtes HTTP par le biais de la librairie si nécessaire



<small><i><a href='http://ecotrust-canada.github.io/markdown-toc/'>Table of contents generated with markdown-toc</a></i></small>
8 changes: 7 additions & 1 deletion exemple/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import axios, { AxiosRequestConfig } from 'axios';
import React, { useState } from 'react';
import { Button, Text, View } from 'react-native';
import { useDispatch } from 'react-redux';
import { ResponseFetchApi, Rh2AxiosConfig, rh2AxiosConfigService } from '../src';
import { ResponseFetchApi, Rh2AxiosConfig, rh2AxiosConfigService, rh2DirectoryService } from '../src';
import { Rh2EffectAxiosConfigHandler } from '../src/models/Rh2Effect';
import { useRh2WithName } from '../src/services/Rh2EffectsService';
import { pourTestAction } from './redux/rh2-action';
Expand Down Expand Up @@ -182,6 +182,12 @@ const traitementErreur = (data: ResponseFetchApi) => {
const test = useRh2WithName(GOOGLE);
console.log(test);

console.log(rh2DirectoryService.getConfigQueryParameters());

rh2DirectoryService.removeAllQueryDirectory();
console.log(rh2DirectoryService.getConfigQueryParameters());



// rh2ConfigService.setErrorHandler(traitementErreur);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-http-request-handler",
"version": "1.0.2",
"version": "1.0.3",
"private": false,
"license": "MIT",
"repository": {
Expand Down
55 changes: 54 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,39 @@

[French documentation](https://github.com/Lunotte/react-http-request-handler/blob/Documentation/docs/readme-fr.md)

## Table of Contents
- [Contexte](#contexte)
- [Functionalities](#functionalities)
- [Installation](#installation)
- [Configurations](#configurations)
* [Library usage](#library-usage)
+ [You can initialize your application by :](#you-can-initialize-your-application-by--)
* [Using two hooks](#using-two-hooks)
+ [Hooks without preloading](#hooks-without-preloading)
- [Other example :](#other-example--)
- [Handling error example](#handling-error-example)
+ [Preloaded Hook](#preloaded-hook)
* [Hook with parameters](#hook-with-parameters)
* [Axios instance](#axios-instance)
* [Services](#services)
+ [Rh2DirectoryService](#rh2directoryservice)
+ [Rh2ConfigService](#rh2configservice)
+ [Rh2AxiosConfigService](#rh2axiosconfigservice)
* [Rh2 model list](#rh2-model-list)
+ [Parameters for non-preloaded requests](#parameters-for-non-preloaded-requests)
- [Rh2EffectAxiosConfigHandler](#rh2effectaxiosconfighandler)
- [Rh2EffectData](#rh2effectdata)
+ [AxiosConfig](#axiosconfig)
+ [FetchApi](#fetchapi)
- [ResponseFetchApi](#responsefetchapi)
- [ErreurFetchApi](#erreurfetchapi)
+ [General configuration](#general-configuration)
- [Rh2InitializationParameter](#rh2initializationparameter)
- [AxiosRequestConfigExtended](#axiosrequestconfigextended)
+ [Rh2InitializationParameter](#rh2initializationparameter-1)
+ [AxiosRequestConfigExtended](#axiosrequestconfigextended-1)
- [Roadmap](#roadmap)

## Contexte

This React library using customized hooks is aimed to help users handling HTTP requests. The request and its trigger are simply configured, then executed by Axios. Optional parameters can also be configured depending on the web client needs.
Expand Down Expand Up @@ -350,6 +383,22 @@ rh2AxiosConfigService.addAuthToConfigAxios(GOOGLE, {

### Services

#### Rh2DirectoryService

Initialize the app :

- Management of requests stored in memory to prevent them from being executed again

| Méthode | type | Description |
| ------------------------------------------------------------ | ---------------------- | --------------------------------------- |
| hasConfigQueryParameter(url: string, method: MethodRnhrh, params?: ParamRnhnh) | boolean | Check the presence of the configuration |
| hasConfigQueryParameterByConfigQueryParameter(parameter: ConfigQueryParameter) | boolean | Check the presence of the configuration |
| addConfigQueryParameter(configTmp: ConfigQueryParameter) | void | Add a configuration to the directory |
| getConfigQueryParameters() | ConfigQueryParameter[] | Retrieve the list of configurations |
| getConfigQueryParameter(url: string, method: MethodRnhrh, params?: ParamRnhnh) | ConfigQueryParameter | Retrieve a specific configuration |
| removeQueryDirectory(axiosRequestConfig: AxiosRequestConfig) | void | Delete a specific configuration |
| removeAllQueryDirectory() | void | Delete all configurations in memory |

#### Rh2ConfigService

Initialize the app :
Expand Down Expand Up @@ -406,7 +455,7 @@ export interface Rh2EffectAxiosConfigHandler {

<b>axiosRequestConfig</b> Axios configuration.

<b>addToDirectory</b> This is used if we want to execute once the request during runtime. This value can be updated with <b>QueryStorageService</b>.
<b>addToDirectory</b> This is used if we want to execute once the request during runtime. This value can be updated with <b>Rh2DirectoryService</b>.

| Caution : The request filter depends on URL, method type and params property. |
| ------------------------------------------------------------ |
Expand Down Expand Up @@ -589,3 +638,7 @@ const initSettings: Rh2InitializationParameter = {

- Modifying an Axios instance to handle new éléments (ex : update « auth » parameter from Axios)
- Handling HTTP request cancellation with the library



<small><i><a href='http://ecotrust-canada.github.io/markdown-toc/'>Table of contents generated with markdown-toc</a></i></small>
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@ export type {
ErreurFetchApi, KeyValue, ResponseFetchApi, Rh2AxiosConfig, Rh2EffectAxiosConfigHandler, Rh2InitializationParameter
} from './models';
export { default as InitializerRnhrh } from './Rh2Initializer';
export { rh2AxiosConfigService, rh2ConfigService } from './services';
export { useRh2WithName, useRh2WithParameters } from './services/Rh2EffectsService';
export { rh2AxiosConfigService, rh2ConfigService, rh2DirectoryService, useRh2WithName, useRh2WithParameters } from './services';

3 changes: 2 additions & 1 deletion src/models/Rh2Effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export interface Rh2EffectData {

/**
* @param keyOfInstance If is not provided, first Axios instance will be used
* @param config Axios settings
* @param axiosRequestConfig Axios settings
* @param addToDirectory Add the query to the directory to prevent a query from running multiple times
* @param onlyResult If true or not defined then return data else all information about http request
* @param errorHandler Method to be executed to handle the errors in the event of an error in the request. If it is not provided, we see if that of the global * configuration is provided otherwise, nothing is done.
* @param successHandler
Expand Down
1 change: 1 addition & 0 deletions src/services/Rh2EffectsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ async function traitementToManageRequest(
const configAxios = configuration.axiosRequestConfig;
const configTmp = configToManageDirectory(configAxios);

// Requête declenchée si filtre à true et que la requête n'est pas déjà envoyée
if (filter && !rh2DirectoryService.hasConfigQueryParameterByConfigQueryParameter(configTmp)) {

isDebugModeThenDisplayInfo(`State filter is ${filter} and configuration is`, configuration);
Expand Down
6 changes: 2 additions & 4 deletions src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
*/






export { default as rh2AxiosConfigService } from './Rh2AxiosConfigService';
export { default as rh2ConfigService } from './Rh2ConfigService';
export { default as rh2DirectoryService } from './Rh2DirectoryService';
export { useRh2WithName, useRh2WithParameters } from './Rh2EffectsService';