- [API] Segregated API files, Implemented spells-list, component that calls the API
This commit is contained in:
7
client/api/api.js
Normal file
7
client/api/api.js
Normal file
@@ -0,0 +1,7 @@
|
||||
import axios from "axios"
|
||||
|
||||
const url = "http://localhost:2814/api"
|
||||
|
||||
export default axios.create({
|
||||
baseURL: url
|
||||
})
|
||||
11
client/api/repositories.js
Normal file
11
client/api/repositories.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import spellsRepository from './spellsRepository'
|
||||
|
||||
// List of possible repositories
|
||||
const repositories = {
|
||||
spells: spellsRepository
|
||||
}
|
||||
|
||||
// Usage : RepositoryFactoryInstance.get('reponame');
|
||||
export const RepositoryFactory = {
|
||||
get: name => repositories[name]
|
||||
}
|
||||
14
client/api/spellsRepository.js
Normal file
14
client/api/spellsRepository.js
Normal file
@@ -0,0 +1,14 @@
|
||||
import api from './api'
|
||||
|
||||
// URL for spells
|
||||
const resource = "/spells"
|
||||
|
||||
// CRUD methods for spells
|
||||
export default {
|
||||
getSpells() {
|
||||
return api.get(`${resource}`)
|
||||
},
|
||||
getSpell(id) {
|
||||
return api.get(`${resource}?id=${id}`)
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user