Created
February 2, 2023 02:19
-
-
Save skeltonmod/ad18af26d0f630c09882624b5181bf52 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "regenerator-runtime/runtime"; | |
import axios from "axios"; | |
// It just appends the API request | |
let cors_api_url = "https://thewashapi-production.up.railway.app/api"; | |
export class Api { | |
static instance; | |
axiosInstance = null; | |
constructor() { | |
this.axiosInstance = axios.create({ | |
// timeout: 30000, | |
baseURL: cors_api_url, | |
headers: { | |
'Content-Type': 'application/json', | |
}, | |
}); | |
// Set interceptors | |
this.axiosInstance.interceptors.request.use( | |
(config) => { | |
return config; | |
}, | |
(error) => { | |
return Promise.reject(error); | |
} | |
); | |
} | |
static getInstance() { | |
if (!Api.instance) { | |
Api.instance = new Api(); | |
} | |
return Api.instance; | |
} | |
static getAxios() { | |
return Api.getInstance().axiosInstance; | |
} | |
static get(url, params, config) { | |
return Api.getAxios().get(url, { params, ...config }); | |
} | |
static post(url, data, config) { | |
// console.log("data req ====>", data); | |
return Api.getAxios().post(url, data, config); | |
} | |
static delete(url, params = {}, config = {}) { | |
return Api.getAxios().delete(url, { params, ...config }); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Api as APIRequest } from "./APIRequest"; | |
const routes = { | |
fetchAnime: async (keyword) => { | |
return await APIRequest.post( | |
`/v2/search-anime`, | |
{ search: keyword }, | |
{ | |
headers: { | |
"Content-Type": "application/x-www-form-urlencoded", | |
}, | |
} | |
).then((r) => r.data); | |
}, | |
fetchMovie: async (keyword) => { | |
return await APIRequest.post( | |
`/v2/search-flick`, | |
{ search: keyword }, | |
{ | |
headers: { | |
"Content-Type": "application/x-www-form-urlencoded", | |
}, | |
} | |
).then((r) => r.data); | |
}, | |
fetchSeries: async (keyword) => { | |
return await APIRequest.post( | |
`/v2/search-series`, | |
{ search: keyword }, | |
{ | |
headers: { | |
"Content-Type": "application/x-www-form-urlencoded", | |
}, | |
} | |
).then((r) => r.data); | |
}, | |
fetchAnimeEpisodes: async (id) => { | |
return await APIRequest.get(`/v2/load-anime/${id}`).then((r) => r.data); | |
}, | |
playAnimeEpisode: async (id) => { | |
return await APIRequest.get(`/v2/play-anime/${id}`).then((r) => r.data); | |
}, | |
}; | |
export default routes; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment