08.02.2017 Views

vuejs

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Preface 96<br />

$ php artisan db:seed;<br />

# Start server<br />

$ php artisan serve --port=3000 --host localhost;<br />

Great! You now have a fully functional API and a database filled with nice stories.<br />

Note<br />

I you are using Vagrant you have to run the server on host ‘0.0.0.0’. Then, you will be able<br />

to access your server on Vagrant’s box ip.<br />

If, for example, Vagrant’s box ip is 192.168.10.10 and you run<br />

$ php artisan serve --port=3000 --host 0.0.0.0;<br />

you can browse your website on 192.168.10.10:3000.<br />

If you have downloaded our demo API, you can continue to the next section.<br />

If you chose to create you own API, you have to create a database table to store the stories. The<br />

following columns must be present.<br />

Column Name<br />

id<br />

plot<br />

writer<br />

upvotes<br />

Type<br />

Integer, Auto Increment<br />

String<br />

String<br />

Integer, Unsigned<br />

Don’t forget to seed some fake data to follow up with the next examples.<br />

8.2.2 API Endpoints<br />

An endpoint is simply a URL. When you go to http://example.com/foo/bar then that is an endpoint<br />

and you simply need to call it /foo/bar because the domain will be the same for all the endpoints.<br />

To manage the Story resource we need 5 endpoints. Each endpoint corresponds to a specific action.<br />

HTTP Method URI Action<br />

GET/HEAD api/stories Fetches all stories<br />

GET/HEAD api/stories/{id} Fetches specified story<br />

POST api/stories Creates a new story<br />

PUT/PATCH api/stories/{id} Updates an existing story<br />

DELETE api/stories/{id} Deletes specified story

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

Saved successfully!

Ooh no, something went wrong!