diff --git a/booker/app.py b/booker/app.py index 7dc3d12..f5245fd 100644 --- a/booker/app.py +++ b/booker/app.py @@ -4,6 +4,25 @@ from flask_cors import CORS # config DEBUG = True +BOOKS = [ + { + 'title': 'On the Road', + 'author': 'Jack Kerouac', + 'read': True + }, + { + 'title': 'Harry Potter and the Philosopher\'s Stone', + 'author': 'J. K. Rowling', + 'read': False + }, + { + 'title': 'Green Eggs and Ham', + 'author': 'Dr. Seuss', + 'read': True + } +] + + # app init app = Flask(__name__) app.config.from_object(__name__) @@ -18,5 +37,13 @@ def ping_route(): return jsonify('You pass butter') +@app.route('/books', methods=['GET']) +def all_books(): + return jsonify({ + 'status': 'success', + 'books': BOOKS + }) + + if __name__ == '__main__': app.run() diff --git a/client/src/App.vue b/client/src/App.vue index 3c3abf7..e2e0448 100644 --- a/client/src/App.vue +++ b/client/src/App.vue @@ -2,7 +2,8 @@
diff --git a/client/src/app.service.js b/client/src/app.service.js new file mode 100644 index 0000000..e8dacb7 --- /dev/null +++ b/client/src/app.service.js @@ -0,0 +1,41 @@ +import axios from 'axios' + +axios.defaults.baseURL = 'http://localhost:5000' + +// To avoid adding the token to every request we make to a service we can +// instead use an interceptor +axios.interceptors.request.use(function (config) { + // added for when the code is running on a server for serverside rendering + if (typeof window === 'undefined') { + return config + } + const token = window.localStorage.getItem('token') + if (token) { + config.headers.Authorization = `Bearer ${token}` + } + + return config +}) + +const appService = { + getPing() { + return new Promise((resolve) => { + axios.get('/ping') + .then(response => { + resolve(response.data) + }) + .catch(error => {alert(error)}) + }) + }, + getAllBooks() { + return new Promise((resolve) => { + axios.get('/books') + .then(response => { + resolve(response.data) + }) + .catch(error => {alert(error)}) + }) + } +} + +export default appService \ No newline at end of file diff --git a/client/src/components/Books.vue b/client/src/components/Books.vue index 74dae7d..8be8969 100644 --- a/client/src/components/Books.vue +++ b/client/src/components/Books.vue @@ -17,18 +17,52 @@ - - foo - bar - foobar - - - - - + + {{ book.title }} + {{ book.author }} + + Yes + No + + + + + + - \ No newline at end of file + + + + + \ No newline at end of file diff --git a/client/src/components/Ping.vue b/client/src/components/Ping.vue index 66c31c6..86c2b11 100644 --- a/client/src/components/Ping.vue +++ b/client/src/components/Ping.vue @@ -5,7 +5,7 @@