ERRest: The Basics Pascal Robert MacTI.ca Our agenda What is REST - - PowerPoint PPT Presentation

errest the basics
SMART_READER_LITE
LIVE PREVIEW

ERRest: The Basics Pascal Robert MacTI.ca Our agenda What is REST - - PowerPoint PPT Presentation

MONTREAL JUNE 30, JULY 1ST AND 2ND 2012 ERRest: The Basics Pascal Robert MacTI.ca Our agenda What is REST ? Basic ERRest concepts Our Model of the day Routes for basic operations REST ? REpresentational State Transfer


slide-1
SLIDE 1

MONTREAL JUNE 30, JULY 1ST AND 2ND 2012

ERRest: The Basics

Pascal Robert MacTI.ca

slide-2
SLIDE 2

Our agenda

  • What is REST ?
  • Basic ERRest concepts
  • Our Model of the day
  • Routes for basic operations
slide-3
SLIDE 3

REST ?

  • REpresentational State Transfer
  • Architecture style, not a protocol or format
slide-4
SLIDE 4

REST and URLs

  • Goal: having consistent and logical URLs that have a meaning
  • GitHub is good example:
  • https://github.com/projectwonder/wonder
  • https://github.com/projectwonder/wonder/admin
slide-5
SLIDE 5

REST and HTTP protocol

  • Goal: to use as much as possible the HTTP protocol
  • Use HTTP verbs
  • Use headers
  • Use redirection
  • Read the spec (RFC 2616)!
slide-6
SLIDE 6

REST and stateless

  • Goal: to be stateless
  • Avoid storing stuff in sessions
  • Back button friendly :-)
  • More scalable (Ramsey will disagree)
slide-7
SLIDE 7

REST and representations

  • Goal: to deliver representations (JSON, XML, etc.) with the same

URL

  • HTML view: https://github.com/projectwonder/wonder/commit/

386d19e3080695d309e676d66db99e271c90dbab

  • Git patch view: https://github.com/projectwonder/wonder/

commit/386d19e3080695d309e676d66db99e271c90dbab.patch

slide-8
SLIDE 8

HTTP verbs

  • Goal: to use the many HTTP verbs
  • Use GET to get representation of data
  • Use POST on a collection to create new data
  • Use PUT to update data
  • Use DELETE to delete data
  • Can use the other verbs (OPTIONS, etc.) too
slide-9
SLIDE 9

HATEOAS

  • HATEOAS (Hypermedia As The Engine of Application State) is

the "full" REST

  • Goal: doing the same as a browser (start page, follow links)
  • One endpoint, and links to other resources
  • Examples: Atom Publishing, CMIS, Google Docs APIs
  • Not currently supported by ERRest
slide-10
SLIDE 10

ERRest concepts

slide-11
SLIDE 11

Key concepts

  • Routes : the paths (URLs) to get/create/update/delete data
  • Controllers : based on a DirectAction class
  • Formats : the representations (JSON, XML, etc.)
  • Filters : which attributes are in and out
slide-12
SLIDE 12

Routes

  • You register them in the REST request handler (/ra)
  • Handler class is: ERXRouteRequestHandler
  • Can have bindings in them
  • /ra/posts/{title:String}
  • /ra/posts/{post:Post}
  • Can register default (CRUD) routes in one step
slide-13
SLIDE 13

Controllers

  • A controller is like a DirectAction class
  • A route is mapped to one method in a controller
  • Base classes: ERXRouteController and ERXDefaultRouteController
slide-14
SLIDE 14

Formats

  • Format is the representation
  • Many formats are supported (JSON, XML, plist, etc.)
  • You can add your own
  • Base class: ERXFormat
slide-15
SLIDE 15

Filters

  • Filtering is to specify what's in the object graph
  • Can have different filters per route and in/out
  • Useful to hide sensible information
  • You use ERXKeyFilter for filtering
slide-16
SLIDE 16

CRUD

  • Extends from controller from ERXDefaultRouteController
  • Register your routes with

restRequestHandler.addDefaultRoutes(Entity.ENTITY_NAME)

slide-17
SLIDE 17

Let's create a REST service

slide-18
SLIDE 18

The Model

  • Example will be a blog system
  • Entities:
  • BlogEntry
  • Author
  • Category
slide-19
SLIDE 19

The Model

slide-20
SLIDE 20

Project Setup

slide-21
SLIDE 21

Adding basic routes

slide-22
SLIDE 22

Basic routes

  • Adding an author
  • Adding a category
  • Adding a blog post
  • Fetching a blog post
  • Updating a blog post
  • Deleting a blog post
slide-23
SLIDE 23

Basic routes setup and usage

slide-24
SLIDE 24

Query arguments

slide-25
SLIDE 25

ERXRestFetchSpecification

  • ERXRestFetchSpecification gives you automatic query

arguments management

  • Built-in arguments:
  • sort=lastModified|desc,title|asc
  • batchSize=25&batch=1
  • qualifier=title%3D'WOWODC'
  • Range=items%3D10-19
slide-26
SLIDE 26

Manual query arguments

  • Same as direct actions: request().stringFormValueForKey
  • A "login" action is such an example
slide-27
SLIDE 27

Query arguments demo

slide-28
SLIDE 28

Tomorrow

  • HTML routes
  • Alias, non-EO and fake primary keys
  • Handling status codes
  • Handling redirections
  • Handling headers
slide-29
SLIDE 29

Q&A

MONTREAL JUNE 30, JULY 1ST AND 2ND 2012