Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // services/request.ts
- import axios from 'axios';
- // Crear una instancia de Axios con configuraciones predeterminadas
- const apiClient = axios.create({
- baseURL: '/proxy/example', // URL Api
- headers: {
- 'Content-Type': 'application/json',
- },
- withCredentials: true
- });
- // Método para peticiones GET
- export const get = async (url: string, params = {}) => {
- try {
- const response = await apiClient.get(url, { params, withCredentials: true });
- return response.data;
- } catch (error) {
- throw error;
- }
- };
- // Método para peticiones POST
- export const post = async (url: string, data: any) => {
- try {
- const response = await apiClient.post(url, data, { withCredentials: true });
- return response.data;
- } catch (error) {
- throw error;
- }
- };
- // Método para peticiones PUT
- export const put = async (url: string, data: any) => {
- try {
- const response = await apiClient.put(url, data, { withCredentials: true });
- return response.data;
- } catch (error) {
- throw error;
- }
- };
- // Método para peticiones PATCH
- export const patch = async (url: string, data: any) => {
- try {
- const response = await apiClient.patch(url, data, { withCredentials: true });
- return response.data;
- } catch (error) {
- throw error;
- }
- };
- // Método para peticiones DELETE
- export const remove = async (url: string) => {
- try {
- const response = await apiClient.delete(url, { withCredentials: true });
- return response.data;
- } catch (error) {
- throw error;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment