Skip to content

Commit

Permalink
BREAKING CHANGE: new API interaction
Browse files Browse the repository at this point in the history
- Удалена функция api.
- Новый формат взаимодействия с API, разделяя обращения к методам на роуты. К тому же, никакого fetch - теперь это Axios.
  • Loading branch information
LukasAndreano committed Sep 15, 2024
1 parent 59bdf2e commit 87c8901
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VITE_BACKEND_URL=https://app-backend.koka.team
VITE_BACKEND_URL=https://api.sampleapis.com/
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@vkontakte/icons": "^2.139.0",
"@vkontakte/vk-bridge": "^2.15.0",
"@vkontakte/vkui": "^6.7.0",
"axios": "^1.7.7",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-hot-toast": "^2.4.1",
Expand Down
15 changes: 15 additions & 0 deletions src/api/api.instance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import axios from "axios";

export const NETWORK = axios.create({
baseURL: import.meta.env.VITE_BACKEND_URL,
timeout: 5e3,
validateStatus: () => true,
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${
window.location.href
.slice(window.location.href.indexOf("?") + 1)
.split("#")[0]
}`,
},
});
3 changes: 3 additions & 0 deletions src/api/routes/route.coffee.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { NETWORK } from "../api.instance";

export const getCoffeeList = () => NETWORK.get("coffee/hot");
38 changes: 0 additions & 38 deletions src/modules/apiRequest.js

This file was deleted.

12 changes: 12 additions & 0 deletions src/panels/home/home.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
import { useRouterModal, useRouterPanel } from "@kokateam/router-vkminiapps";
import { Button, Title } from "@vkontakte/vkui";
import toast from "react-hot-toast";
import { useEffect } from "react";
import { getCoffeeList } from "../../api/routes/route.coffee.js";

const Home = () => {
const [, toModal] = useRouterModal();
const [, toPanel] = useRouterPanel();

const fetchCoffee = async () => {
const { data } = await getCoffeeList();

console.log(`API Coffee List Example: `, data);
};

useEffect(() => {
fetchCoffee();
}, []);

return (
<>
<Title weight={"3"} className={"mb10 centered"}>
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ axios@^0.21.1:
dependencies:
follow-redirects "^1.14.0"

axios@^1.7.5:
axios@^1.7.5, axios@^1.7.7:
version "1.7.7"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.7.7.tgz#2f554296f9892a72ac8d8e4c5b79c14a91d0a47f"
integrity sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==
Expand Down

0 comments on commit 87c8901

Please sign in to comment.