-
Notifications
You must be signed in to change notification settings - Fork 26
[김참솔] Sprint7-1 #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The head ref may contain hidden characters: "React-\uAE40\uCC38\uC194-sprint8"
[김참솔] Sprint7-1 #106
Changes from all commits
1c593f8
b8a39ea
850fa84
a5d8953
0077ff5
ea52a34
d197fe4
8d68359
72184dc
4d4fa1c
843b0e0
2b0a85c
64277f9
ab5f2e0
a1834dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| function trimPath(str) { | ||
| let trimmed = str.trim(); | ||
| while (trimmed.startsWith("/")) { | ||
| trimmed = trimmed.slice(1); | ||
| } | ||
| return trimmed; | ||
| } | ||
|
|
||
| function createUrl(baseUrl, path, searchParams) { | ||
| const trimmed = trimPath(path); | ||
| const url = new URL(`${baseUrl}/${trimmed}`); | ||
|
|
||
| if (!searchParams) { | ||
| return url; | ||
| } | ||
|
|
||
| Object.keys(searchParams).forEach((key) => | ||
| url.searchParams.append(key, searchParams[key]) | ||
| ); | ||
|
|
||
| return url; | ||
| } | ||
|
|
||
| class HttpClient { | ||
| constructor({ baseUrl }) { | ||
| this.baseUrl = baseUrl; | ||
| } | ||
|
|
||
| async get(target, params) { | ||
| let url; | ||
| if (this.baseUrl) { | ||
| url = createUrl(this.baseUrl, target, params); | ||
| } else { | ||
| url = target; | ||
| } | ||
|
|
||
| const response = await fetch(url, { method: "GET" }); | ||
| if (!response.ok) { | ||
| throw new Error(`HTTP error (status ${response.status}`); | ||
| } | ||
|
|
||
| const json = await response.json(); | ||
| return json; | ||
| } | ||
| } | ||
|
|
||
| export default HttpClient; | ||
|
|
||
| const client = new HttpClient({ baseUrl: import.meta.env.VITE_API_BASE_URL }); | ||
|
|
||
| export { client }; | ||
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { BrowserRouter, Route, Routes } from "react-router-dom"; | ||
| import HomeLayout from "./layouts/home-layout/home-layout"; | ||
| import AddItemPage from "./pages/add-item/add-item-page"; | ||
| import ItemDetailPage from "./pages/items/item-detail-page"; | ||
| import ItemsPage from "./pages/items/items-page"; | ||
| import "./styles/global.css"; | ||
| import "./styles/palette.css"; | ||
|
|
||
| function App() { | ||
| return ( | ||
| <BrowserRouter> | ||
| <HomeLayout> | ||
| <Routes> | ||
| <Route path="/items" element={<ItemsPage />} /> | ||
| <Route path="/items/:id" element={<ItemDetailPage />} /> | ||
| <Route path="/additem" element={<AddItemPage />} /> | ||
| <Route path="*" element={<h1>NOT IMPLEMENTED</h1>} /> | ||
| </Routes> | ||
| </HomeLayout> | ||
| </BrowserRouter> | ||
| ); | ||
| } | ||
|
|
||
| export default App; |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
크으 직접 만들어보시는걸 택하셨군요 👍👍
훌륭한 도전입니다.
get에 대해서 잘 작성하셨네요 👍