Skip to content

Commit

Permalink
feat: Added axios client
Browse files Browse the repository at this point in the history
  • Loading branch information
miguel-merlin committed Feb 13, 2024
1 parent 7d6c9a6 commit 7a9e652
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/api/apiClient.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import axios, { type AxiosRequestConfig } from 'axios'

const apiClient = axios.create({
baseURL: 'http://localhost:8080',
headers: {
Accept: 'application/json',
'Content-type': 'application/json'
}
} satisfies AxiosRequestConfig)

export default apiClient
21 changes: 21 additions & 0 deletions src/api/lib/users.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import apiClient from '../apiClient'

export const getAllUsers = async (): Promise<unknown> => {
return await apiClient.get('/all')
}

export const getUser = async (id: string): Promise<unknown> => {
return await apiClient.get(`/${id}`)
}

export const createUser = async (user: unknown): Promise<unknown> => {
return await apiClient.post('/', JSON.stringify(user))
}

export const updateUser = async (id: string, user: unknown): Promise<unknown> => {
return await apiClient.put(`/${id}`, JSON.stringify(user))
}

export const deleteUser = async (id: string): Promise<unknown> => {
return await apiClient.delete(`/${id}`)
}

0 comments on commit 7a9e652

Please sign in to comment.