-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add axios and configure api requests
- Loading branch information
Showing
6 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import axios from 'axios'; | ||
import { | ||
requestInterceptor, | ||
responseSuccessInterceptor, | ||
responseErrorInterceptor, | ||
} from './interceptors'; | ||
|
||
function Factory(baseURL) { | ||
const instance = axios.create({ | ||
baseURL, | ||
}); | ||
|
||
instance.interceptors.request.use(requestInterceptor); | ||
|
||
instance.interceptors.response.use( | ||
responseSuccessInterceptor, | ||
responseErrorInterceptor, | ||
); | ||
|
||
return instance; | ||
} | ||
|
||
export default Factory; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import Factory from './factory'; | ||
|
||
const coreApiUrl = 'https://api.themoviedb.org/3'; | ||
const commonInstance = Factory(coreApiUrl); | ||
|
||
export default commonInstance; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const requestInterceptor = config => config; | ||
|
||
const responseSuccessInterceptor = response => response.data; | ||
|
||
const responseErrorInterceptor = (error) => { | ||
const response = error.response || error; | ||
return Promise.reject(response); | ||
}; | ||
|
||
export { | ||
requestInterceptor, | ||
responseSuccessInterceptor, | ||
responseErrorInterceptor, | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import axios from '@/axios'; | ||
|
||
export const getMovies = ({ page = 1 }) => axios.get(`/movie/popular?api_key=${process.env.REACT_APP_API_MOVIE_DB}&language=pt-BR&page=${page}`); | ||
|
||
export const getMovieSimilarly = ({ page = 1, id }) => axios.get(`/movie/${id}/similar?api_key=${process.env.REACT_APP_API_MOVIE_DB}&language=pt-BR&page=${page}`); | ||
|
||
export const getMovieDetails = id => axios.get(`/movie/${id})movie/${id}?api_key=${process.env.REACT_APP_API_MOVIE_DB}&language=pt-BR&page=1`); | ||
|
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
1e649f0
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.
Successfully deployed to the following URLs: