Reader small image

You're reading from  Laravel 5.x Cookbook

Product typeBook
Published inSep 2016
Reading LevelIntermediate
PublisherPackt
ISBN-139781786462084
Edition1st Edition
Languages
Tools
Right arrow
Authors (2):
Terry Matula
Terry Matula
author image
Terry Matula

Terry Matula is a web developer and Laravel advocate based in Austin, TX. He's been a passionate computer enthusiast since he first played Oregon Trail on an Apple//e. He started programming in BASIC at a young age, making simple Scott Adams-like games on a Commodore Vic-20. Since then, he's worked as a developer using Flash/ActionScript, ASP.NET, PHP, and numerous PHP frameworks, with Laravel being his favorite by far. He blogs web development tips and tricks at his website http://terrymatula.com
Read more about Terry Matula

Alfred Nutile
Alfred Nutile
author image
Alfred Nutile

Alfred Nutile is an Enterprise Architect and Laravel lead based in Western Massachusetts. He's been working in the industry since the mid 90's. He started in PHP and MySQL back around that time and has worked with Ruby on Rails, Drupal, and Angular along the way. He introduced Laravel into an enterprise web stack, where he is currently contracted at, as Laravel proved itself as an amazing framework to build API's and Angular heavy application. You can read more about him and checkout his blog at http://www.alfrednutile.info/ or follow him on Twitter at https://twitter.com/alnutile Make sure to checkout the discount LaraCasts is offering those who buy the book! Get a coupon for 50% on your first bill. Make it a yearly subscription and save $43! Coupon Code: LaracastsLovesPackt https://laracasts.com/signup?plan=yearly&coupon=LaracastsLovesPackt.
Read more about Alfred Nutile

View More author details
Right arrow

Building an API / JSON based route for searching


In Chapter 6, Adding Angular to Your App we will cover Angular and in there I needed to make an API for the widget to talk to. Let's review that again here in more detail.

Getting ready

A fresh install of Laravel will do.

How to do it...

Follow the steps to build an API / JSON route for searching:

  1. Add our controller:

    > php artisan make:controller SearchComics
    
  2. Add our route:

  3. Fill in the controller:

  4. And in the ComicClientInterface class, I handle the comics method like this. I will go into more details in the How it works… section:

  5. Show it working at the UI level http://recipes.dev/api/v1/search:

    Figure 1 Example of JSON Response from Search

How it works…

First, I will go over what I did above but then I will show another example to simplify it more.

As usual, I made the controller and plugged in the route. Note I use api/v1/ as a route prefix. This just helps me later on do a breaking API change at /api/v2. There are other ways to do this but for now...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Laravel 5.x Cookbook
Published in: Sep 2016Publisher: PacktISBN-13: 9781786462084

Authors (2)

author image
Terry Matula

Terry Matula is a web developer and Laravel advocate based in Austin, TX. He's been a passionate computer enthusiast since he first played Oregon Trail on an Apple//e. He started programming in BASIC at a young age, making simple Scott Adams-like games on a Commodore Vic-20. Since then, he's worked as a developer using Flash/ActionScript, ASP.NET, PHP, and numerous PHP frameworks, with Laravel being his favorite by far. He blogs web development tips and tricks at his website http://terrymatula.com
Read more about Terry Matula

author image
Alfred Nutile

Alfred Nutile is an Enterprise Architect and Laravel lead based in Western Massachusetts. He's been working in the industry since the mid 90's. He started in PHP and MySQL back around that time and has worked with Ruby on Rails, Drupal, and Angular along the way. He introduced Laravel into an enterprise web stack, where he is currently contracted at, as Laravel proved itself as an amazing framework to build API's and Angular heavy application. You can read more about him and checkout his blog at http://www.alfrednutile.info/ or follow him on Twitter at https://twitter.com/alnutile Make sure to checkout the discount LaraCasts is offering those who buy the book! Get a coupon for 50% on your first bill. Make it a yearly subscription and save $43! Coupon Code: LaracastsLovesPackt https://laracasts.com/signup?plan=yearly&coupon=LaracastsLovesPackt.
Read more about Alfred Nutile