08.02.2017 Views

vuejs

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

8. Preface<br />

In this chapter, we are going to go a little deeper and demonstrate how we can use Vue.js to consume<br />

an API.<br />

Following the story examples of previous chapters, we will now use some real data, coming from an<br />

external source.<br />

In order to use real data, we need to make use of a database. Assuming that you already know how<br />

to create a database, it won’t be covered in this book. To work along with the book’s examples, we<br />

got you covered, we have already created one to be put to use.<br />

8.1 CRUD<br />

Presume we have a database, we need to perform CRUD operations (Create, Read, Update, Delete).<br />

More particularly, we want to<br />

• Create new stories in the database<br />

• Read existing stories<br />

• Update existing story’s details (such as ‘upvotes’)<br />

• Delete stories that we don’t like<br />

Since Vue.js is a Front-end JavaScript framework, it cannot connect to a database directly. To access a<br />

database we need a layer between Vue.js and the database, this layer is the API (Application Program<br />

Interface).<br />

8.2 API<br />

Because this book is about Vue.js and not about designing APIs, we will provide you a demo API<br />

built with Laravel¹. Laravel is one of most powerful PHP frameworks along with Symfony2, Nette,<br />

CodeIgniter, and Yii2. You are free to create your API using any language or framework you like. I<br />

use Laravel because it is simple, it has a great community, and it is awesome! :)<br />

Therefore, we strongly recommend to use the demo API that we have built exclusively for the book’s<br />

examples.<br />

¹https://laravel.com/<br />

94

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!