using restful apis in angularjs

17
Using RESTful APIs in AngularJS Presenter: Jyotirmaya Dehury, Mindfire Solutions Date: 07/30/2014

Upload: mindfire-solutions

Post on 10-Sep-2014

411 views

Category:

Software


4 download

DESCRIPTION

SPA(Single-page application) web-solutions are now a days the new standard of web development, becoming more and more popular and narrowing down the difference between a desktop and web application. JavaScript libraries/frameworks like Backbone, Knockout, Angular along with RESTful web APIs provide a great platform to develop SPA web-solutions.

TRANSCRIPT

Page 1: Using RESTFUL APIs in ANGULARJS

Using RESTful APIs in AngularJS

Presenter: Jyotirmaya Dehury, Mindfire SolutionsDate: 07/30/2014

Page 2: Using RESTFUL APIs in ANGULARJS

1. REST Concepts.

2. CRUD(create, read, update, and delete) with REST.

3. Basics of AngularJS

4. Consuming RESTful APIs using ngResource module in AngularJS.

5. Demo App.

Agenda

Presenter: Jyotirmaya Dehury, Mindfire Solutions

Page 3: Using RESTFUL APIs in ANGULARJS

REST ConceptsREST is a standard to be followed.Helps you to build an API that is efficient, easy to use and HIGHLY UNDERSTANDABLE.

RESOURCE-oriented model to expose their services.

Create a uniform interface by mapping HTTP methods to CRUD

CRUD = Create, Read, Update, Delete

HTTP methods = POST, GET, PUT, DELETE

Create = POSTRead = GETUpdate = PUTDelete = DELETE

Presenter: Jyotirmaya Dehury, Mindfire Solutions

Page 4: Using RESTFUL APIs in ANGULARJS

REST ConceptsSo instead of API calls such as:

Create – POST: /user/newRead – GET: /user?id=1Update – POST: /user/updateDelete – GET: /user/delete?id=1

Simply:

Create – POST: /user (with the variables in the entity-body)Read – GET: /user/1Update – PUT: /user/1 (with the variables in the entity-body)Delete – DELETE: /user/1

Presenter: Jyotirmaya Dehury, Mindfire Solutions

Page 5: Using RESTFUL APIs in ANGULARJS

REST Concepts

Consider the following:

POST: http:/test.com/userGET: http:/test.com/user/1PUT: http:/test.com/user/1DELETE: http:/test.com/user/1

POST, GET, PUT, DELETE are the methods

http:/test.com/user, http:/test.com/user/1 are URI’s

user/1 is a user, which is a resource

Understand Resources and REST URI

Presenter: Jyotirmaya Dehury, Mindfire Solutions

Page 6: Using RESTFUL APIs in ANGULARJS

REST Concepts

Difference between a resource and a representation:

GET: http:/test.com/user/1 will return a Representation{"firstName":"John", "lastName":"Doe"}

Of the resource user:1.

A representation will have a format like JSON or XML.

A client application gets a REPRESENTATION of the resource using the REST URI

Presenter: Jyotirmaya Dehury, Mindfire Solutions

Page 7: Using RESTFUL APIs in ANGULARJS

AngularJS

A great framework to develop SPA web-solutions.

An MVC framework.

A JavaScript framework to develop web applications.

Presenter: Jyotirmaya Dehury, Mindfire Solutions

Page 8: Using RESTFUL APIs in ANGULARJS

AngularJS Angular Features

Presenter: Jyotirmaya Dehury, Mindfire Solutions

ServerAP

Is

Page 9: Using RESTFUL APIs in ANGULARJS

AngularJS

Its a JavaScript object.Angular services help to build reusable business logic which can be shared and used across the app.

Angular Services

$http$resource$q$anchorScroll$cacheFactory$compile$parse$locale

$timeout$exceptionHandler$filter$cookieStore

$route$routeParams$location

● Built-In Services

Presenter: Jyotirmaya Dehury, Mindfire Solutions● Custom Services

Page 10: Using RESTFUL APIs in ANGULARJS

AngularJS

The ngResource module provides interaction support with RESTful services via the $resource service.

ngResource

Installation

<script src=”angular.js”><script src=”angular-resource.js”>

Presenter: Jyotirmaya Dehury, Mindfire Solutions

Page 11: Using RESTFUL APIs in ANGULARJS

AngularJS

Creates a resource object that lets you interact with RESTful server-side data sources.

$resource

$resource(url, [paramDefaults], [actions], options);

var User = $resource('/user/:userId', {userId:'@id'});var user = User.get({userId:123});// GET: /user/123

Presenter: Jyotirmaya Dehury, Mindfire Solutions

Page 12: Using RESTFUL APIs in ANGULARJS

AngularJS

Creates a resource object that lets you interact with RESTful server-side data sources.

$resource

$resource(url, [paramDefaults], [actions], options);

{ 'get' : {method: 'GET' }, 'save' : {method: 'POST' }, 'query' : {method: 'GET' , isArray:true}, 'remove' : {method: 'DELETE' }, 'delete' : {method: 'DELETE' } };

Presenter: Jyotirmaya Dehury, Mindfire Solutions

Page 13: Using RESTFUL APIs in ANGULARJS

Demo

Presenter: Jyotirmaya Dehury, Mindfire Solutions

Page 14: Using RESTFUL APIs in ANGULARJS

Questions?

Presenter: Jyotirmaya Dehury, Mindfire Solutions

Page 15: Using RESTFUL APIs in ANGULARJS

http://www.pluralsight.com/

https://docs.angularjs.org/api/ngResource/service/$resource

http://mark-kirby.co.uk/2013/creating-a-true-rest-api/

IBM – RESTful Web Services: The Basics

https://www.youtube.com/watch?v=QHIMygADPPc

References

Presenter: Jyotirmaya Dehury, Mindfire Solutions

Page 16: Using RESTFUL APIs in ANGULARJS

Presenter: Jyotirmaya Dehury, Mindfire Solutions

Thank you

Page 17: Using RESTFUL APIs in ANGULARJS

www.mindfiresolutions.com

https://www.facebook.com/MindfireSolutions

http://www.linkedin.com/company/mindfire-solutions

http://twitter.com/mindfires