Skip to content

Instantly share code, notes, and snippets.

@skeltonmod
Created February 2, 2023 02:19
Show Gist options
  • Save skeltonmod/ad18af26d0f630c09882624b5181bf52 to your computer and use it in GitHub Desktop.
Save skeltonmod/ad18af26d0f630c09882624b5181bf52 to your computer and use it in GitHub Desktop.
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 });
}
}
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