Skip to content

Commit b8aaa84

Browse files
authored
Merge pull request #4 from neylorxt/dev
V0.0.2
2 parents 6b179e0 + cb39392 commit b8aaa84

5 files changed

Lines changed: 85 additions & 2 deletions

File tree

README.fr.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,25 @@ if (response.success) {
9292
}
9393
```
9494

95+
### `deleteData(url, config)`
96+
97+
Pour supprimer (DELETE) des données.
98+
99+
- **`url`** : L'adresse du serveur.
100+
- **`config`** (optionnel) : Configuration Axios (par exemple, pour les en-têtes).
101+
102+
**Exemple :**
103+
104+
```javascript
105+
import { deleteData } from '@neylorxt/react-api';
106+
107+
const response = await deleteData('https://api.example.com/posts/1');
108+
109+
if (response.success) {
110+
console.log('Article supprimé :', response.data);
111+
}
112+
```
113+
95114
### `sendRequest(url, options)`
96115

97116
C'est la fonction "couteau suisse". Elle peut tout faire !

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,25 @@ if (response.success) {
9090
}
9191
```
9292

93+
### `deleteData(url, config)`
94+
95+
Use this function to delete data (HTTP DELETE).
96+
97+
- **`url`**: The API endpoint to call.
98+
- **`config`** (optional): An Axios config object, e.g., for passing headers.
99+
100+
**Example:**
101+
102+
```javascript
103+
import { deleteData } from '@neylorxt/react-api';
104+
105+
const response = await deleteData('https://api.example.com/posts/1');
106+
107+
if (response.success) {
108+
console.log('Post deleted:', response.data);
109+
}
110+
```
111+
93112
### `sendRequest(url, options)`
94113

95114
This is a general-purpose function that can handle any type of HTTP request.

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@neylorxt/react-api",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"description": "It's a mini package that makes it easy for you to send data via axios.",
55
"keywords": [
66
"neylorxt",

src/index.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,51 @@ export async function updateData(url, data = {}, config = {}) {
188188
}
189189

190190

191+
/**
192+
* Update data using axios (PUT)
193+
*
194+
* @param {string} url - The endpoint URL
195+
* @param {object} [data={}] - The data to send in the request body
196+
* @param {object} [config={}] - Additional Axios config (headers, params, etc.)
197+
* @returns {Promise<{ success: boolean, status: number, data: any, headers: object }>}
198+
*
199+
* @example
200+
* const data = { name: "Neylorxt" };
201+
* { name: 'Sword', rarity: 'legendary' },
202+
* {
203+
* headers: {
204+
* Authorization: `Bearer ${token}`
205+
* },
206+
* params: {
207+
* debug: true,
208+
* lang: 'fr'
209+
* }
210+
* }
211+
* const response = await updateData("https://api.example.com/user/123", data, config);
212+
*/
213+
export async function deleteData(url, data = {}, config = {}) {
214+
try {
215+
const { method, data, ...safeConfig } = config; // on retire toute méthode fournie
216+
217+
const axiosConfig = {
218+
...safeConfig,
219+
data: data,
220+
params: config.params || {} // s'assurer que params existe
221+
};
222+
const response = await axios.delete(url, axiosConfig); // ✅ config peut inclure headers + params
223+
224+
return {
225+
success: true,
226+
status: response.status,
227+
data: response.data,
228+
headers: response.headers
229+
};
230+
231+
} catch (error) {
232+
233+
return formatAxiosError(error);
234+
}
235+
}
191236

192237

193238

0 commit comments

Comments
 (0)