SlideShare a Scribd company logo
1 of 48
Download to read offline
MONTREAL JUNE 30, JULY 1ST AND 2ND 2012




ERRest in Depth
Pascal Robert
MacTI.ca
The Menu

ā€¢   Request/response loop

ā€¢   Behavior changes

ā€¢   Formats

ā€¢   Transactions

ā€¢   Same Origin Policy

ā€¢   Date and time management
Request handling
Request
               Application.dispatchRequest




ERXRouteRequestHandler(WOActionRequestHandler).handleR
                       equest




 YourController(ERXRouteController).performActionNamed
performActionNamed
checkAccess()



ā€¢   Default implementation in ERXRouteController does nothing

ā€¢   Override it in your controller for security check
performHtmlActionNamed

ā€¢   Does <EntityName><ActionName>Page component exists?

    ā€¢   No: fall back to controller

    ā€¢   Yes: Check if component implements IEXRouteComponent

        ā€¢   Yes: return the component

        ā€¢   No: fall back to controller
shouldFailOnMissingHtmlPage


ā€¢   Does the component was not found or don't implement
    IEXRouteComponent?

    ā€¢   If shouldFailOnMissingHtmlPage() returns true, call
        performUnknownAction (will return a 404 NotFound)

    ā€¢   Default is false, override it in your controller if needed.
performRouteActionNamed


ā€¢   Try to ļ¬nd <actionName>Action method.

    ā€¢   Not found? Try to ļ¬nd <actionName> method.

    ā€¢   Still nothing? Check for annotations.

    ā€¢   Still nothing? Call performUnknownAction

    ā€¢   Got something? Call performActionWithArguments
performUnknownAction


ā€¢   if (ERXRest.strictMode)

    ā€¢   throw ERXNotAllowedException (HTTP code 405)

ā€¢   else

    ā€¢   throw FileNotFoundException (HTTP code 404)
performActionWithArguments




ā€¢   Will invoke the method with the arguments
Objects management
Objects in routes

ā€¢   /ra/<entityName>/{entity:EntityName}

ā€¢   routeObjectForKey(key)

ā€¢   create(ļ¬lter)

ā€¢   update(object, ļ¬lter)
routeObjectForKey


ā€¢   {<keyName>:<keyType>} in route = keyType result =
    routeObjectForKey(<keyName>)

ā€¢   Object is obtained by ERXRestUtils.coerceValueToTypeNamed
coerceValueToTypeNamed

ā€¢   Where value is transformed to a object or primitive

ā€¢   If it's an EO or POJO, will use
    ERXRestClassDescriptionFactory.classDescriptionForEntityName to ļ¬nd the
    class

ā€¢   Will call
    IERXRestDelegate.Factory.delegateForClassDescription().objectOfEntityWithI
    D()
create(ļ¬lter)

ā€¢   Will call ERXRestClassDescriptionFactory.classDescriptionForEntityName

ā€¢   Will call
    IERXRestDelegate.Factory.delegateForClassDescription().createObjectOfEnti
    tyWithID to create a basic EO/POJO

ā€¢   Will call updateObjectWithFilter()
update(object, ļ¬lter)



ā€¢   As with create(ļ¬lter), will simply call updateObjectWithFilter
updateObjectWithFilter



ā€¢   Major method

ā€¢   Will take content from request and update object (PUT request)

ā€¢   Also used to populate new object (POST request)
Response handling
response(object, ļ¬lter)


ā€¢   Will built up the object graph with
    ERXRestRequestNode.requestNodeWithObjectAndFilter

ā€¢   Will call response(format, responseNode)
requestNodeWithObjectAndFilter




ā€¢   If primitive/simple object, will set the value

ā€¢   If EO/POJO, will call _ļ¬llInWithObjectAndFilter
_ļ¬llInWithObjectAndFilter



ā€¢   If object is an array, method take itself

ā€¢   If not array, will use object's delegate to call primaryKeyForObject, and
    call _addAttributesAndRelationshipsForObjectOfEntity
response(format, responseNode)



ā€¢   Returns result of ERXRouteResults(context, restContext, format,
    responseNode)

ā€¢   ERXRouteResults.generateResponse() will actually generate the response
    in requested format
response(ERXRestFetchSpeciļ¬cation,
                 ļ¬lter)


ā€¢   Useful to return list of objects ("index" action)
ā€¢   ERXRestFetchSpeciļ¬cation allow you to set ordering, range, ļ¬ltering and
    batching from request

ā€¢   Will also call response(format, responseNode)
response(int)


ā€¢   Use that one to send a response without any content in the body

ā€¢   Check ERXHttpStatusCodes
There's a property for that
"id" key


ā€¢   ERXRest.idKey : what to use instead of "id"
    Default: {"id":2 }
    ERRest.idKey=primaryKey {"primaryKey":2 }
"nil" key
ā€¢   ERXRest.nilKey
    To rewrite the "nil" attribute
    Default: <someAttribute nil="true"/>

    ERXRest.nilKey=cestVide -> <someAttribute cestVide="true"/>

ā€¢   ERXRest.writeNilKey
    Skip the "nil" attribute
    Default: <someAttribute nil="true"/>

    ERXRest.writeNilKey=false -> <someAttribute nil="true"/>
"type" key
ā€¢   ERXRest.typeKey
    Allow you to change the name of the "type" attribute

    Default: {"type":"NameOfEntity"}

    ERXRest.typeKey=entityName {"entityName":"NameOfEntity"}

ā€¢   ERXRest.writeTypeKey
    If false, won't write the "type" attribute in the response

    ERXRest.writeTypeKey=false -> {id: 2, "type":"NameOfEntity"}
ERXRest.pluralEntityNames


ā€¢   Default is true

ā€¢   If set to false, can't use pluralized names
    Default: /ra/restEntities

    Set to false: /ra/restEntities
ERXRest.suppressTypeAttributesForSimpl
                   eTypes
ā€¢   Only for XML format

ā€¢   Default value is false

ā€¢   Default rendering:
    <RestEntity primaryKey="1">
     <someAttribute type = "integer">2</someAttribute>
    </RestEntity>

ā€¢   When set to false:
    <RestEntity primaryKey="1">
     <someAttribute type = "integer">2</someAttribute>
ERXRest.strictMode


ā€¢   Default is: true

ā€¢   For missing route, will send 405 (Not Allowed) code, if set to false,
    will send 404 (Not Found)

ā€¢   POST requests: will send 201 (Created), if false will send 200 (OK)
ERXRest.routeCase

ā€¢   ERXRest.routeCase=LowerCamelCase
    /ra/restEntities

ā€¢   ERXRest.routeCase=CamelCase
    /ra/RestEntities

ā€¢   ERXRest.routeCase=LowercaseUnderscore
    /ra/rest_entities
ERXRest.parseUnknownExtensions


ā€¢   /ra/restEntities/3.fsdfsd

ā€¢   If set to true (the default):
    HTTP/1.1 200 Apple WebObjects

    Content-Type: text/html

ā€¢   If set to false:
    HTTP/1.0 400 Apple WebObjects
Formats
ERXRest.defaultFormat



ā€¢   ERXRest.defaultFormat=json|xml|plist|html|...

ā€¢   Let you specify the default format for all controllers

ā€¢   Can override it per controller:
    protected ERXRestFormat defaultFormat() {
        return ERXRestFormat.json();
    }
Format detection

ā€¢   Format detection is in ERXRouteController.format()

ā€¢   Order of detection

    ā€¢   From extension (.json). Set in
        ERXRouteRequestHandler.routeForMethodAndPath()

    ā€¢   From the Content-Type header

    ā€¢   Default format (defaultFormat() in controller)
Adding new format


ā€¢   Your own private format? Use
    ERXRestFormat.registerFormatNamed()

ā€¢   Format useful for the commumity? Add them to ERXRestFormat
Same Domain Policy
Same Origin Policy

ā€¢   Problem: browsers won't load data if client and server not on same
    domain

ā€¢   Numerous ways: window.name transport, JSONP and Cross-origin
    resource sharing (CORS)

ā€¢   CORS and window.name transport support is part of ERRest
CORS

ā€¢   Works with Gecko 1.9.1 (Firefox 3.5+), WebKit (Safari 4+, Google
    Chrome 3+), Opera 12 and IE 8+

ā€¢   Send extra headers to server

ā€¢   Client speciļ¬y origin, requested HTTP verb and allowed headers,
    server returns allowed origin, methods, headers and max-age
CORS preļ¬‚ight
Client request:

OPTIONS /resources/post-here/ HTTP/1.1
Origin: http://foo.example
Access-Control-Request-Method: POST
Access-Control-Request-Headers: X-PINGOTHER

Server response:

HTTP/1.1 200 OK
Access-Control-Allow-Origin: http://foo.example
Access-Control-Allow-Methods: POST, GET, OPTIONS
Access-Control-Allow-Headers: X-PINGOTHER
Access-Control-Max-Age: 1728000

Client request:

GET /resources/post-here/ HTTP/1.1
Origin: http://foo.example

Server response:

HTTP/1.1 200 OK
Access-Control-Allow-Origin: http://foo.example
CORS

ā€¢   ERXRest.accessControlAllowRequestHeaders

ā€¢   ERXRest.accessControlAllowRequestMethods

ā€¢   ERXRest.accessControlMaxAge (default: 1728000)

ā€¢   ERXRest.accessControlAllowOrigin ('*' to allow all)
window.name Transport

ā€¢   Dojo use that trick

ā€¢   Client send ?windowname=true in URL

ā€¢   Enable it on server with:
    ERXRest.allowWindowNameCrossDomainTransport=true

ā€¢   Will wrap response in HTML code:
    <html><script type="text/javascript">window.name='{"id":
    4,"type":"RestEntity","someAttribute":"commit transaction"}';</script></html>
Status codes
Status code and exceptions
ā€¢   ObjectNotAvailableException, FileNotFoundException,
    NoSuchElementException: returns a 404 (Not Found)

ā€¢   SecurityException: returns a 403 (Forbidden)

ā€¢   ERXNotAllowedException: returns a 405 (Method Not Allowed)

ā€¢   ERXValidationException, NSValidation.ValidationException: returns a 400 (Bad
    Request)

ā€¢   Anything else: returns a 500 (Internal Server Error)

ā€¢   Avoid sending 5xx codes if the client made a mistake!
Adding support for new data types

ā€¢   Add a processor in _ERXJSONConļ¬g

ā€¢   Add support code in ERXRestUtils
    ā€¢   isPrimitive()

    ā€¢   coerceValueToString()

    ā€¢   coerceValueToTypeNamed

ā€¢   For dates: add formatter in ERXRestUtils
MONTREAL JUNE 30, JULY 1ST AND 2ND 2012




Q&A

More Related Content

What's hot

Web Š²ŠµŃŠ½Š° 2013 Š»ŠµŠŗцŠøя 6
Web Š²ŠµŃŠ½Š° 2013 Š»ŠµŠŗцŠøя 6Web Š²ŠµŃŠ½Š° 2013 Š»ŠµŠŗцŠøя 6
Web Š²ŠµŃŠ½Š° 2013 Š»ŠµŠŗцŠøя 6
Technopark
Ā 
QA Lab: тŠµŃŃ‚ŠøрŠ¾Š²Š°Š½ŠøŠµ ŠŸŠž. ŠÆŠŗŠ¾Š² ŠšŃ€Š°Š¼Š°Ń€ŠµŠ½ŠŗŠ¾: "KISS Automation"
QA Lab: тŠµŃŃ‚ŠøрŠ¾Š²Š°Š½ŠøŠµ ŠŸŠž. ŠÆŠŗŠ¾Š² ŠšŃ€Š°Š¼Š°Ń€ŠµŠ½ŠŗŠ¾: "KISS Automation"QA Lab: тŠµŃŃ‚ŠøрŠ¾Š²Š°Š½ŠøŠµ ŠŸŠž. ŠÆŠŗŠ¾Š² ŠšŃ€Š°Š¼Š°Ń€ŠµŠ½ŠŗŠ¾: "KISS Automation"
QA Lab: тŠµŃŃ‚ŠøрŠ¾Š²Š°Š½ŠøŠµ ŠŸŠž. ŠÆŠŗŠ¾Š² ŠšŃ€Š°Š¼Š°Ń€ŠµŠ½ŠŗŠ¾: "KISS Automation"
GeeksLab Odessa
Ā 
Web Š¾ŃŠµŠ½ŃŒ 2012 Š»ŠµŠŗцŠøя 6
Web Š¾ŃŠµŠ½ŃŒ 2012 Š»ŠµŠŗцŠøя 6Web Š¾ŃŠµŠ½ŃŒ 2012 Š»ŠµŠŗцŠøя 6
Web Š¾ŃŠµŠ½ŃŒ 2012 Š»ŠµŠŗцŠøя 6
Technopark
Ā 
Django Pro ORM
Django Pro ORMDjango Pro ORM
Django Pro ORM
Alex Gaynor
Ā 
Developing Useful APIs
Developing Useful APIsDeveloping Useful APIs
Developing Useful APIs
Dmitry Buzdin
Ā 

What's hot (20)

QA Lab: тŠµŃŃ‚ŠøрŠ¾Š²Š°Š½ŠøŠµ ŠŸŠž. Š”тŠ°Š½ŠøсŠ»Š°Š² ŠØŠ¼ŠøŠ“т: "Self-testing REST APIs with API Fi...
QA Lab: тŠµŃŃ‚ŠøрŠ¾Š²Š°Š½ŠøŠµ ŠŸŠž. Š”тŠ°Š½ŠøсŠ»Š°Š² ŠØŠ¼ŠøŠ“т: "Self-testing REST APIs with API Fi...QA Lab: тŠµŃŃ‚ŠøрŠ¾Š²Š°Š½ŠøŠµ ŠŸŠž. Š”тŠ°Š½ŠøсŠ»Š°Š² ŠØŠ¼ŠøŠ“т: "Self-testing REST APIs with API Fi...
QA Lab: тŠµŃŃ‚ŠøрŠ¾Š²Š°Š½ŠøŠµ ŠŸŠž. Š”тŠ°Š½ŠøсŠ»Š°Š² ŠØŠ¼ŠøŠ“т: "Self-testing REST APIs with API Fi...
Ā 
Web Š²ŠµŃŠ½Š° 2013 Š»ŠµŠŗцŠøя 6
Web Š²ŠµŃŠ½Š° 2013 Š»ŠµŠŗцŠøя 6Web Š²ŠµŃŠ½Š° 2013 Š»ŠµŠŗцŠøя 6
Web Š²ŠµŃŠ½Š° 2013 Š»ŠµŠŗцŠøя 6
Ā 
Solr workshop
Solr workshopSolr workshop
Solr workshop
Ā 
Jstl Guide
Jstl GuideJstl Guide
Jstl Guide
Ā 
QA Lab: тŠµŃŃ‚ŠøрŠ¾Š²Š°Š½ŠøŠµ ŠŸŠž. ŠÆŠŗŠ¾Š² ŠšŃ€Š°Š¼Š°Ń€ŠµŠ½ŠŗŠ¾: "KISS Automation"
QA Lab: тŠµŃŃ‚ŠøрŠ¾Š²Š°Š½ŠøŠµ ŠŸŠž. ŠÆŠŗŠ¾Š² ŠšŃ€Š°Š¼Š°Ń€ŠµŠ½ŠŗŠ¾: "KISS Automation"QA Lab: тŠµŃŃ‚ŠøрŠ¾Š²Š°Š½ŠøŠµ ŠŸŠž. ŠÆŠŗŠ¾Š² ŠšŃ€Š°Š¼Š°Ń€ŠµŠ½ŠŗŠ¾: "KISS Automation"
QA Lab: тŠµŃŃ‚ŠøрŠ¾Š²Š°Š½ŠøŠµ ŠŸŠž. ŠÆŠŗŠ¾Š² ŠšŃ€Š°Š¼Š°Ń€ŠµŠ½ŠŗŠ¾: "KISS Automation"
Ā 
Web Š¾ŃŠµŠ½ŃŒ 2012 Š»ŠµŠŗцŠøя 6
Web Š¾ŃŠµŠ½ŃŒ 2012 Š»ŠµŠŗцŠøя 6Web Š¾ŃŠµŠ½ŃŒ 2012 Š»ŠµŠŗцŠøя 6
Web Š¾ŃŠµŠ½ŃŒ 2012 Š»ŠµŠŗцŠøя 6
Ā 
How to write easy-to-test JavaScript
How to write easy-to-test JavaScriptHow to write easy-to-test JavaScript
How to write easy-to-test JavaScript
Ā 
ExtJs Basic Part-1
ExtJs Basic Part-1ExtJs Basic Part-1
ExtJs Basic Part-1
Ā 
55 New Features in Java 7
55 New Features in Java 755 New Features in Java 7
55 New Features in Java 7
Ā 
Http4s, Doobie and Circe: The Functional Web Stack
Http4s, Doobie and Circe: The Functional Web StackHttp4s, Doobie and Circe: The Functional Web Stack
Http4s, Doobie and Circe: The Functional Web Stack
Ā 
Object Oriented Exploitation: New techniques in Windows mitigation bypass
Object Oriented Exploitation: New techniques in Windows mitigation bypassObject Oriented Exploitation: New techniques in Windows mitigation bypass
Object Oriented Exploitation: New techniques in Windows mitigation bypass
Ā 
Codegeneration With Xtend
Codegeneration With XtendCodegeneration With Xtend
Codegeneration With Xtend
Ā 
JSP Standart Tag LÄ°brary - JSTL
JSP Standart Tag LÄ°brary - JSTLJSP Standart Tag LÄ°brary - JSTL
JSP Standart Tag LÄ°brary - JSTL
Ā 
Django Pro ORM
Django Pro ORMDjango Pro ORM
Django Pro ORM
Ā 
Introduction to Active Record - Silicon Valley Ruby Conference 2007
Introduction to Active Record - Silicon Valley Ruby Conference 2007Introduction to Active Record - Silicon Valley Ruby Conference 2007
Introduction to Active Record - Silicon Valley Ruby Conference 2007
Ā 
J query
J queryJ query
J query
Ā 
Using the Tooling API to Generate Apex SOAP Web Service Clients
Using the Tooling API to Generate Apex SOAP Web Service ClientsUsing the Tooling API to Generate Apex SOAP Web Service Clients
Using the Tooling API to Generate Apex SOAP Web Service Clients
Ā 
Advanced Django ORM techniques
Advanced Django ORM techniquesAdvanced Django ORM techniques
Advanced Django ORM techniques
Ā 
Developing Useful APIs
Developing Useful APIsDeveloping Useful APIs
Developing Useful APIs
Ā 
J query1
J query1J query1
J query1
Ā 

Similar to ERRest in Depth

Hidden Treasures in Project Wonder
Hidden Treasures in Project WonderHidden Treasures in Project Wonder
Hidden Treasures in Project Wonder
WO Community
Ā 
Lucene for Solr Developers
Lucene for Solr DevelopersLucene for Solr Developers
Lucene for Solr Developers
Erik Hatcher
Ā 
Data Access Options in SharePoint 2010
Data Access Options in SharePoint 2010Data Access Options in SharePoint 2010
Data Access Options in SharePoint 2010
Rob Windsor
Ā 
Concurrency and Thread-Safe Data Processing in Background Tasks
Concurrency and Thread-Safe Data Processing in Background TasksConcurrency and Thread-Safe Data Processing in Background Tasks
Concurrency and Thread-Safe Data Processing in Background Tasks
WO Community
Ā 
appengine java night #1
appengine java night #1appengine java night #1
appengine java night #1
Shinichi Ogawa
Ā 
Appengine Java Night #2a
Appengine Java Night #2aAppengine Java Night #2a
Appengine Java Night #2a
Shinichi Ogawa
Ā 
Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012
Michelangelo van Dam
Ā 

Similar to ERRest in Depth (20)

Hidden Treasures in Project Wonder
Hidden Treasures in Project WonderHidden Treasures in Project Wonder
Hidden Treasures in Project Wonder
Ā 
Lucene for Solr Developers
Lucene for Solr DevelopersLucene for Solr Developers
Lucene for Solr Developers
Ā 
Tutorial, Part 3: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
Tutorial, Part 3: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...Tutorial, Part 3: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
Tutorial, Part 3: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
Ā 
Data Access Options in SharePoint 2010
Data Access Options in SharePoint 2010Data Access Options in SharePoint 2010
Data Access Options in SharePoint 2010
Ā 
More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)
More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)
More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)
Ā 
Developer testing 101: Become a Testing Fanatic
Developer testing 101: Become a Testing FanaticDeveloper testing 101: Become a Testing Fanatic
Developer testing 101: Become a Testing Fanatic
Ā 
AJAX.ppt
AJAX.pptAJAX.ppt
AJAX.ppt
Ā 
Phoenix + React恧 ē¤¾å†…ć‚·ć‚¹ćƒ†ćƒ ć‚’ åÆ†ć‹ć«ä½œć£ć¦ć‚‹
Phoenix + React恧 ē¤¾å†…ć‚·ć‚¹ćƒ†ćƒ ć‚’ åÆ†ć‹ć«ä½œć£ć¦ć‚‹Phoenix + React恧 ē¤¾å†…ć‚·ć‚¹ćƒ†ćƒ ć‚’ åÆ†ć‹ć«ä½œć£ć¦ć‚‹
Phoenix + React恧 ē¤¾å†…ć‚·ć‚¹ćƒ†ćƒ ć‚’ åÆ†ć‹ć«ä½œć£ć¦ć‚‹
Ā 
Custom EOAdaptors and ERSolr
Custom EOAdaptors and ERSolrCustom EOAdaptors and ERSolr
Custom EOAdaptors and ERSolr
Ā 
Requery overview
Requery overviewRequery overview
Requery overview
Ā 
AJAX Transport Layer
AJAX Transport LayerAJAX Transport Layer
AJAX Transport Layer
Ā 
Building High Performance Web Applications and Sites
Building High Performance Web Applications and SitesBuilding High Performance Web Applications and Sites
Building High Performance Web Applications and Sites
Ā 
Tutorial on developing a Solr search component plugin
Tutorial on developing a Solr search component pluginTutorial on developing a Solr search component plugin
Tutorial on developing a Solr search component plugin
Ā 
Concurrency and Thread-Safe Data Processing in Background Tasks
Concurrency and Thread-Safe Data Processing in Background TasksConcurrency and Thread-Safe Data Processing in Background Tasks
Concurrency and Thread-Safe Data Processing in Background Tasks
Ā 
Refactoring
RefactoringRefactoring
Refactoring
Ā 
appengine java night #1
appengine java night #1appengine java night #1
appengine java night #1
Ā 
Appengine Java Night #2a
Appengine Java Night #2aAppengine Java Night #2a
Appengine Java Night #2a
Ā 
Local data storage for mobile apps
Local data storage for mobile appsLocal data storage for mobile apps
Local data storage for mobile apps
Ā 
Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012
Ā 
Full Text Search In PostgreSQL
Full Text Search In PostgreSQLFull Text Search In PostgreSQL
Full Text Search In PostgreSQL
Ā 

More from WO Community

In memory OLAP engine
In memory OLAP engineIn memory OLAP engine
In memory OLAP engine
WO Community
Ā 
Using Nagios to monitor your WO systems
Using Nagios to monitor your WO systemsUsing Nagios to monitor your WO systems
Using Nagios to monitor your WO systems
WO Community
Ā 
Build and deployment
Build and deploymentBuild and deployment
Build and deployment
WO Community
Ā 
High availability
High availabilityHigh availability
High availability
WO Community
Ā 
Chaining the Beast - Testing Wonder Applications in the Real World
Chaining the Beast - Testing Wonder Applications in the Real WorldChaining the Beast - Testing Wonder Applications in the Real World
Chaining the Beast - Testing Wonder Applications in the Real World
WO Community
Ā 
D2W Stateful Controllers
D2W Stateful ControllersD2W Stateful Controllers
D2W Stateful Controllers
WO Community
Ā 
Deploying WO on Windows
Deploying WO on WindowsDeploying WO on Windows
Deploying WO on Windows
WO Community
Ā 
Unit Testing with WOUnit
Unit Testing with WOUnitUnit Testing with WOUnit
Unit Testing with WOUnit
WO Community
Ā 
Life outside WO
Life outside WOLife outside WO
Life outside WO
WO Community
Ā 
Apache Cayenne for WO Devs
Apache Cayenne for WO DevsApache Cayenne for WO Devs
Apache Cayenne for WO Devs
WO Community
Ā 
Advanced Apache Cayenne
Advanced Apache CayenneAdvanced Apache Cayenne
Advanced Apache Cayenne
WO Community
Ā 
Migrating existing Projects to Wonder
Migrating existing Projects to WonderMigrating existing Projects to Wonder
Migrating existing Projects to Wonder
WO Community
Ā 
iOS for ERREST - alternative version
iOS for ERREST - alternative versioniOS for ERREST - alternative version
iOS for ERREST - alternative version
WO Community
Ā 
iOS for ERREST
iOS for ERRESTiOS for ERREST
iOS for ERREST
WO Community
Ā 
"Framework Principal" pattern
"Framework Principal" pattern"Framework Principal" pattern
"Framework Principal" pattern
WO Community
Ā 
Localizing your apps for multibyte languages
Localizing your apps for multibyte languagesLocalizing your apps for multibyte languages
Localizing your apps for multibyte languages
WO Community
Ā 

More from WO Community (20)

In memory OLAP engine
In memory OLAP engineIn memory OLAP engine
In memory OLAP engine
Ā 
Using Nagios to monitor your WO systems
Using Nagios to monitor your WO systemsUsing Nagios to monitor your WO systems
Using Nagios to monitor your WO systems
Ā 
Build and deployment
Build and deploymentBuild and deployment
Build and deployment
Ā 
High availability
High availabilityHigh availability
High availability
Ā 
Reenabling SOAP using ERJaxWS
Reenabling SOAP using ERJaxWSReenabling SOAP using ERJaxWS
Reenabling SOAP using ERJaxWS
Ā 
Chaining the Beast - Testing Wonder Applications in the Real World
Chaining the Beast - Testing Wonder Applications in the Real WorldChaining the Beast - Testing Wonder Applications in the Real World
Chaining the Beast - Testing Wonder Applications in the Real World
Ā 
D2W Stateful Controllers
D2W Stateful ControllersD2W Stateful Controllers
D2W Stateful Controllers
Ā 
Deploying WO on Windows
Deploying WO on WindowsDeploying WO on Windows
Deploying WO on Windows
Ā 
Unit Testing with WOUnit
Unit Testing with WOUnitUnit Testing with WOUnit
Unit Testing with WOUnit
Ā 
Life outside WO
Life outside WOLife outside WO
Life outside WO
Ā 
Apache Cayenne for WO Devs
Apache Cayenne for WO DevsApache Cayenne for WO Devs
Apache Cayenne for WO Devs
Ā 
Advanced Apache Cayenne
Advanced Apache CayenneAdvanced Apache Cayenne
Advanced Apache Cayenne
Ā 
Migrating existing Projects to Wonder
Migrating existing Projects to WonderMigrating existing Projects to Wonder
Migrating existing Projects to Wonder
Ā 
iOS for ERREST - alternative version
iOS for ERREST - alternative versioniOS for ERREST - alternative version
iOS for ERREST - alternative version
Ā 
iOS for ERREST
iOS for ERRESTiOS for ERREST
iOS for ERREST
Ā 
"Framework Principal" pattern
"Framework Principal" pattern"Framework Principal" pattern
"Framework Principal" pattern
Ā 
WOver
WOverWOver
WOver
Ā 
Localizing your apps for multibyte languages
Localizing your apps for multibyte languagesLocalizing your apps for multibyte languages
Localizing your apps for multibyte languages
Ā 
WOdka
WOdkaWOdka
WOdka
Ā 
ERGroupware
ERGroupwareERGroupware
ERGroupware
Ā 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(ā˜Žļø+971_581248768%)**%*]'#abortion pills for sale in dubai@
Ā 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
Ā 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
Ā 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
Ā 

Recently uploaded (20)

DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
Ā 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
Ā 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
Ā 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
Ā 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
Ā 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
Ā 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
Ā 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
Ā 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Ā 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Ā 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
Ā 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Ā 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
Ā 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
Ā 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Ā 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Ā 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Ā 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
Ā 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
Ā 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
Ā 

ERRest in Depth

  • 1. MONTREAL JUNE 30, JULY 1ST AND 2ND 2012 ERRest in Depth Pascal Robert MacTI.ca
  • 2. The Menu ā€¢ Request/response loop ā€¢ Behavior changes ā€¢ Formats ā€¢ Transactions ā€¢ Same Origin Policy ā€¢ Date and time management
  • 4. Request Application.dispatchRequest ERXRouteRequestHandler(WOActionRequestHandler).handleR equest YourController(ERXRouteController).performActionNamed
  • 6. checkAccess() ā€¢ Default implementation in ERXRouteController does nothing ā€¢ Override it in your controller for security check
  • 7. performHtmlActionNamed ā€¢ Does <EntityName><ActionName>Page component exists? ā€¢ No: fall back to controller ā€¢ Yes: Check if component implements IEXRouteComponent ā€¢ Yes: return the component ā€¢ No: fall back to controller
  • 8. shouldFailOnMissingHtmlPage ā€¢ Does the component was not found or don't implement IEXRouteComponent? ā€¢ If shouldFailOnMissingHtmlPage() returns true, call performUnknownAction (will return a 404 NotFound) ā€¢ Default is false, override it in your controller if needed.
  • 9. performRouteActionNamed ā€¢ Try to ļ¬nd <actionName>Action method. ā€¢ Not found? Try to ļ¬nd <actionName> method. ā€¢ Still nothing? Check for annotations. ā€¢ Still nothing? Call performUnknownAction ā€¢ Got something? Call performActionWithArguments
  • 10. performUnknownAction ā€¢ if (ERXRest.strictMode) ā€¢ throw ERXNotAllowedException (HTTP code 405) ā€¢ else ā€¢ throw FileNotFoundException (HTTP code 404)
  • 11. performActionWithArguments ā€¢ Will invoke the method with the arguments
  • 13. Objects in routes ā€¢ /ra/<entityName>/{entity:EntityName} ā€¢ routeObjectForKey(key) ā€¢ create(ļ¬lter) ā€¢ update(object, ļ¬lter)
  • 14. routeObjectForKey ā€¢ {<keyName>:<keyType>} in route = keyType result = routeObjectForKey(<keyName>) ā€¢ Object is obtained by ERXRestUtils.coerceValueToTypeNamed
  • 15. coerceValueToTypeNamed ā€¢ Where value is transformed to a object or primitive ā€¢ If it's an EO or POJO, will use ERXRestClassDescriptionFactory.classDescriptionForEntityName to ļ¬nd the class ā€¢ Will call IERXRestDelegate.Factory.delegateForClassDescription().objectOfEntityWithI D()
  • 16. create(ļ¬lter) ā€¢ Will call ERXRestClassDescriptionFactory.classDescriptionForEntityName ā€¢ Will call IERXRestDelegate.Factory.delegateForClassDescription().createObjectOfEnti tyWithID to create a basic EO/POJO ā€¢ Will call updateObjectWithFilter()
  • 17. update(object, ļ¬lter) ā€¢ As with create(ļ¬lter), will simply call updateObjectWithFilter
  • 18. updateObjectWithFilter ā€¢ Major method ā€¢ Will take content from request and update object (PUT request) ā€¢ Also used to populate new object (POST request)
  • 20. response(object, ļ¬lter) ā€¢ Will built up the object graph with ERXRestRequestNode.requestNodeWithObjectAndFilter ā€¢ Will call response(format, responseNode)
  • 21. requestNodeWithObjectAndFilter ā€¢ If primitive/simple object, will set the value ā€¢ If EO/POJO, will call _ļ¬llInWithObjectAndFilter
  • 22. _ļ¬llInWithObjectAndFilter ā€¢ If object is an array, method take itself ā€¢ If not array, will use object's delegate to call primaryKeyForObject, and call _addAttributesAndRelationshipsForObjectOfEntity
  • 23. response(format, responseNode) ā€¢ Returns result of ERXRouteResults(context, restContext, format, responseNode) ā€¢ ERXRouteResults.generateResponse() will actually generate the response in requested format
  • 24. response(ERXRestFetchSpeciļ¬cation, ļ¬lter) ā€¢ Useful to return list of objects ("index" action) ā€¢ ERXRestFetchSpeciļ¬cation allow you to set ordering, range, ļ¬ltering and batching from request ā€¢ Will also call response(format, responseNode)
  • 25. response(int) ā€¢ Use that one to send a response without any content in the body ā€¢ Check ERXHttpStatusCodes
  • 26. There's a property for that
  • 27. "id" key ā€¢ ERXRest.idKey : what to use instead of "id" Default: {"id":2 } ERRest.idKey=primaryKey {"primaryKey":2 }
  • 28. "nil" key ā€¢ ERXRest.nilKey To rewrite the "nil" attribute Default: <someAttribute nil="true"/> ERXRest.nilKey=cestVide -> <someAttribute cestVide="true"/> ā€¢ ERXRest.writeNilKey Skip the "nil" attribute Default: <someAttribute nil="true"/> ERXRest.writeNilKey=false -> <someAttribute nil="true"/>
  • 29. "type" key ā€¢ ERXRest.typeKey Allow you to change the name of the "type" attribute Default: {"type":"NameOfEntity"} ERXRest.typeKey=entityName {"entityName":"NameOfEntity"} ā€¢ ERXRest.writeTypeKey If false, won't write the "type" attribute in the response ERXRest.writeTypeKey=false -> {id: 2, "type":"NameOfEntity"}
  • 30. ERXRest.pluralEntityNames ā€¢ Default is true ā€¢ If set to false, can't use pluralized names Default: /ra/restEntities Set to false: /ra/restEntities
  • 31. ERXRest.suppressTypeAttributesForSimpl eTypes ā€¢ Only for XML format ā€¢ Default value is false ā€¢ Default rendering: <RestEntity primaryKey="1"> <someAttribute type = "integer">2</someAttribute> </RestEntity> ā€¢ When set to false: <RestEntity primaryKey="1"> <someAttribute type = "integer">2</someAttribute>
  • 32. ERXRest.strictMode ā€¢ Default is: true ā€¢ For missing route, will send 405 (Not Allowed) code, if set to false, will send 404 (Not Found) ā€¢ POST requests: will send 201 (Created), if false will send 200 (OK)
  • 33. ERXRest.routeCase ā€¢ ERXRest.routeCase=LowerCamelCase /ra/restEntities ā€¢ ERXRest.routeCase=CamelCase /ra/RestEntities ā€¢ ERXRest.routeCase=LowercaseUnderscore /ra/rest_entities
  • 34. ERXRest.parseUnknownExtensions ā€¢ /ra/restEntities/3.fsdfsd ā€¢ If set to true (the default): HTTP/1.1 200 Apple WebObjects Content-Type: text/html ā€¢ If set to false: HTTP/1.0 400 Apple WebObjects
  • 36. ERXRest.defaultFormat ā€¢ ERXRest.defaultFormat=json|xml|plist|html|... ā€¢ Let you specify the default format for all controllers ā€¢ Can override it per controller: protected ERXRestFormat defaultFormat() { return ERXRestFormat.json(); }
  • 37. Format detection ā€¢ Format detection is in ERXRouteController.format() ā€¢ Order of detection ā€¢ From extension (.json). Set in ERXRouteRequestHandler.routeForMethodAndPath() ā€¢ From the Content-Type header ā€¢ Default format (defaultFormat() in controller)
  • 38. Adding new format ā€¢ Your own private format? Use ERXRestFormat.registerFormatNamed() ā€¢ Format useful for the commumity? Add them to ERXRestFormat
  • 40. Same Origin Policy ā€¢ Problem: browsers won't load data if client and server not on same domain ā€¢ Numerous ways: window.name transport, JSONP and Cross-origin resource sharing (CORS) ā€¢ CORS and window.name transport support is part of ERRest
  • 41. CORS ā€¢ Works with Gecko 1.9.1 (Firefox 3.5+), WebKit (Safari 4+, Google Chrome 3+), Opera 12 and IE 8+ ā€¢ Send extra headers to server ā€¢ Client speciļ¬y origin, requested HTTP verb and allowed headers, server returns allowed origin, methods, headers and max-age
  • 42. CORS preļ¬‚ight Client request: OPTIONS /resources/post-here/ HTTP/1.1 Origin: http://foo.example Access-Control-Request-Method: POST Access-Control-Request-Headers: X-PINGOTHER Server response: HTTP/1.1 200 OK Access-Control-Allow-Origin: http://foo.example Access-Control-Allow-Methods: POST, GET, OPTIONS Access-Control-Allow-Headers: X-PINGOTHER Access-Control-Max-Age: 1728000 Client request: GET /resources/post-here/ HTTP/1.1 Origin: http://foo.example Server response: HTTP/1.1 200 OK Access-Control-Allow-Origin: http://foo.example
  • 43. CORS ā€¢ ERXRest.accessControlAllowRequestHeaders ā€¢ ERXRest.accessControlAllowRequestMethods ā€¢ ERXRest.accessControlMaxAge (default: 1728000) ā€¢ ERXRest.accessControlAllowOrigin ('*' to allow all)
  • 44. window.name Transport ā€¢ Dojo use that trick ā€¢ Client send ?windowname=true in URL ā€¢ Enable it on server with: ERXRest.allowWindowNameCrossDomainTransport=true ā€¢ Will wrap response in HTML code: <html><script type="text/javascript">window.name='{"id": 4,"type":"RestEntity","someAttribute":"commit transaction"}';</script></html>
  • 46. Status code and exceptions ā€¢ ObjectNotAvailableException, FileNotFoundException, NoSuchElementException: returns a 404 (Not Found) ā€¢ SecurityException: returns a 403 (Forbidden) ā€¢ ERXNotAllowedException: returns a 405 (Method Not Allowed) ā€¢ ERXValidationException, NSValidation.ValidationException: returns a 400 (Bad Request) ā€¢ Anything else: returns a 500 (Internal Server Error) ā€¢ Avoid sending 5xx codes if the client made a mistake!
  • 47. Adding support for new data types ā€¢ Add a processor in _ERXJSONConļ¬g ā€¢ Add support code in ERXRestUtils ā€¢ isPrimitive() ā€¢ coerceValueToString() ā€¢ coerceValueToTypeNamed ā€¢ For dates: add formatter in ERXRestUtils
  • 48. MONTREAL JUNE 30, JULY 1ST AND 2ND 2012 Q&A