14
Laravel + Restangular Let’s do this.

Laravel + Restangular Introduction

Embed Size (px)

DESCRIPTION

This is the presentation I put together for the LaravelDFW September Meetup. I followed the slides with a live demonstration on how to use Laravel + Restangular. The whole presentation can be seen here. http://www.laraveldfw.com/live

Citation preview

Page 1: Laravel + Restangular Introduction

Laravel + RestangularLet’s do this.

Page 2: Laravel + Restangular Introduction

But first

Andrew Del Prete@pathsofdesign

www.pathsofdesign.com

Who am I?

Page 3: Laravel + Restangular Introduction

What we’re covering

• Some of the benefits of Restangular over alternatives

• An intro on how to do basic HTTP requests with Restangular

• A quick review of Laravel Resource Routes

• Build a small SPA (Korra) to demonstrate how it works

• Online resources

• That’s all folks

• Questions

Page 4: Laravel + Restangular Introduction

So what is Restangular?

“Restangular is an AngularJS service that simplifies common GET, POST, DELETE, and UPDATE requests with a minimum of client code. It's a perfect fit for any WebApp that consumes data from a RESTful API.”

https://github.com/mgonto/restangular

Page 5: Laravel + Restangular Introduction

Benefits Much?• Creating a Single Page Application (SPA) is easier than ever.

• Promises Promises.

• A great way to simplify JSON CRUD.

• Utilizes explicit Syntax that is easy to remember.

• Allows you to forget full URLs.

• Supports all HTTP methods.

• Helps the developer throw away the jQuery “Crutch”

• Allows you to chain methods together for complex requests.

• Very configurable / customizable.

And more!

Page 6: Laravel + Restangular Introduction

Can’t I already AJAX?

jQuery offers a great line of AJAXY methods. $.ajax, $.get, $.json, etc… The problem is

these methods are low level and are not abstracted into a reusable service.

$http is the low level AJAX service that’s native to AngularJS. It’s a lot like jQuery’s

AJAX methods but can be injected into Angular and is what Restangular builds upon

internally.

$resource is the native REST Module in AngularJS. It’s difficult to use and buggy.

Restangular aims to solve the flaws of $resource and provide a better service for REST.

The alternatives

Page 7: Laravel + Restangular Introduction

Restangular Requirements

AngularJS

Lodash or Underscore

Page 8: Laravel + Restangular Introduction

Setting up Restangular

Page 9: Laravel + Restangular Introduction

Creating Main Restangular ObjectThere are 3 ways of creating a main Restangular object. The first one and most

common is by stating the main route of all requests. The second one is by stating the

main route and object of all requests. Each object can be built upon and utilized later

in our code to do various requests.

Page 10: Laravel + Restangular Introduction

Get, Post, Put, and Delete

Page 11: Laravel + Restangular Introduction

Chaining Requests

Page 12: Laravel + Restangular Introduction

Let’s Build Something!

Page 13: Laravel + Restangular Introduction

ResourcesKorra - https://github.com/Pathsofdesign/korra The blog experiment I demonstrated. I hope to add features and refine.

Restangular Docs - https://github.com/mgonto/restangularSurprisingly good Documentation!

ng-newsletter - http://www.ng-newsletter.com/posts/restangular.htmlGreat resource for AngularJS all around.

Page 14: Laravel + Restangular Introduction

That’s all Folks!