SlideShare a Scribd company logo
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
REST Development made Easy with ColdFusion Aether
S V Pavan Kumar | sanniset@adobe.com
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
About Pavan
2
Adobe ColdFusion & API Manager Product
Team
Security Czar for ColdFusion Team
Experienced Java Developer
Former Developer at RSA Security
Stewie: What kind of feet can fit into these
shoes?! 
Brian: YOUR FEET!
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 3
ColdFusion Aether
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Agenda
 Writing a Simple Rest Service using CF
 Development Workflow Issues
 What’s new
 Demo
4
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Simple CFC
component output="false" {
public Book function deletebook(required numeric bookid) description="Deletes Specified Book"{
// Function Body
}
public any function getAllBooks() description="Gets list of all Books" {
// Function Body
}
public Book function getBook(required numeric bookid) description="Get Book by ID" {
// Function Body
}
public numeric function addBook(required struct newbook) description="Add a new book" {
// Function Body Err: why can’t I use Book CFC as input argument type instead of struct
}
}
5
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
REST
 REST is about resources and how to represent them in different ways
 REST is about how to manipulate resources
 It’s a architectural style
 Representational state transfer
 It runs on existing standard Http protocol
Methods (GET, PUT, POST, DELETE, PATCH)
HTTP URI Syntax (PATHs, parameters etc.)
Media Types (xml, json, html. text etc.)
HTTP response codes
 ColdFusion offers simple and flexible way of writing REST Web services
6
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
REST API
http://service.com/rest/dw/books
http://service.com/rest/dw/books/{id
}
GET http://service.com/rest/dw/books HTTP/1.
POST http://service.com/rest/dw/books/123
HTTP/1.1
DELETE http://service.com/rest/dw/books/123
HTTP/1.1
<books>
<book id="123",name="Harry Porter">
<author>JK Rowling</author>
</book>
</books>
{
"books":{[{"book":{
"author“ : "JK Rowling",
"id“ : 123
"name“ : "Harry Porter"
}
}]}
}
7
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
CFC as Resource
component restpath="books"
rest="true" output="false" {
// Component Body
}
8
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Function -> REST
public any function getAllBooks() description="Gets all
Books“ httpmethod="GET"
produces= "application/json,application/xml"
{
// Function Body
}
9
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
How the URL is Formed
10
http(s)://<hostname>:[port]/servlet mapping/service mapping/[cfcrestpath]/[methodrestpath]
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Function -> REST
public numeric function addBook(required struct newbook
restargsource="body") description="Add a new book“
consumes="application/json" produces="text/plain"
httpmethod="POST" {
}
11
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
CFArgument
public Book function getBook(required numeric bookid
restargsource = "path" restargname="bookid")
description="Get Book by ID“ restpath="{bookid}"
produces="application/json" httpmethod="GET" {
// Function Body
}
12
http://localhost:8500/rest/dw/books/20
Componentbookid
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Registering REST application
 Register the directory containing the REST service in following ways:
 ColdFusion Administrative Console
 ColdFusion Admin API
 Using restInitApplication
13
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Registering REST application
2.) Admin API : One requires Admin privilege to invoke below functions
 registerRESTService(rootPath, [service mapping])
 getRESTServices() : returns array of REST services registered with ColdFusion
 deleteRESTService(rootPath): Deletes REST service at the specified path
 refreshRESTService(rootPath): If you make any changes to the REST-enabled CF
component, you can refresh the registered application by calling this function.
3.) restInitApplication(rootPath,[serviceMapping])
4.)
14
<cfset this.restsettings.autoregister="true"/>
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Development Issues
15
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
REST Developer Problems
16
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
REST Developer Problems
17
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
REST Developer Problems
18
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
REST Developer Problems
19
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
REST Developer Problems
20
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
REST Developer Problems
21
 Difficulty in exploring the REST URLs (Going through CFCs to derive them)
 http://localhost:8500/rest/servicemapping/shopping/itemcode
 URL has 4 parts – deriving it is a cumbersome work
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
REST Developer Problems
22
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
REST Developer Problems (Swagger)
23
Root Swagger:
http(s)://<hostname>:[port]/servlet mapping/service
mapping/api-docs
Resource Level Swagger:
http(s)://<hostname>:[port]/servlet mapping/service
mapping/api-docs/resource-name
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
REST Developer Problems
 For every change in code developer is forced to login to the ColdFusion
Administrator and refresh the server to test them
 Debugging the Runtime errors used to be difficult
 Digging through the large log files and associating that to the current context used
to be difficult every time.
 Not showing the compilation errors in the admin UI
24
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
REST Developer Problems
 Difficulty in exploring the REST URLs (Going through CFCs to derive them)
 Manually interpreting the Swagger Docs
 No Quick Testing tools
 Gaps in REST Language
25
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Categories of Enhancements
 REST Development friendly Enhancements
 REST Language Enhancements
26
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Developer Profile
27
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
REST Development (Developer Friendly)
 REST services made dynamic
Pros:
-No more refreshes to reflect the changed code
-The behaviour synonymous with normal ColdFusion development
Cons:
- Auto-refresh adds some time lag.
- For production environments user can turn-off this feature.
28
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Tools making REST development faster
 RESTPlay application.
 No login required - Just Enable Developer profile
 Auto listing of the applications and URLs in the app.
 Swagger docs are integrated
http://localhost:8500/restplay
29
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
RESTPlay Application
 Showing the error stack trace now on-the-go
 Show the Compilation errors while registering the application.
30
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
RESTPlay Application-How it eases
31
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
RESTPlay Application-How it eases
32
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
RESTPlay Application-How it eases
33
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
RESTPlay
 From RESTPlay app even in production REST services can be
tested(Precondition-URL should be known)
Ex:- http://localhost:8500/rest/mapping/shopping/restplay
34
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
REST Enhancements
 REST Language Enhancements
35
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
REST Enhancements (Language)
 Support for REST Functions with Component(Bean) as arguments
remote any function setuserPost(student x) httpmethod="POST"
restpath="setuser"
description="Setuser using POST"
{
return x;
}
{
"name": "pavan kumar",
"company": "Adobe Systems"
}
36
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
REST Enhancements
 Support for JSON Patch (rfc6902)
User can submit only the fields that they want to update instead of submitting the whole
object. Request becomes thin.
https://sookocheff.com/post/api/understanding-json-patch/
37
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
JSON Patch
38
Original:
{
"baz": "qux",
"foo": "bar"
}
Patch:
[
{ "op": "replace", "path": "/baz", "value": "boo" },
{ "op": "add", "path": "/hello", "value": ["world"] },
{ "op": "remove", "path": "/foo"}
]
{
"baz": "boo",
"hello": ["world"]
}
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
REST Enhancements
39
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
REST Enhancements
40
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
REST Enhancements
41
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
REST Enhancements
 Entity Filtering support(JSON Field Projection)
User can opt to receive the fields that are of his interest in the response. Response
becomes thin
42
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
REST Enhancements
43
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
REST Enhancements
 Enhanced restSetResponse()
User can set the response even when the function's return type is non-void.
44
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
REST Enhancements
 Support for onRESTRequest life cycle function (Equivalent of onCFCRequest)
- Works as an interceptor to the REST Calls (User can use it for logging/adding security layer)
<cffunction name="onRESTRequest" returntype="any" output="true">
<cfargument type="string" name="cfcname" required=true>
<cfargument type="string" name="method" required=true>
<cfargument type="struct" name="args" required=true>
<cflog text="onRESTRequest() Before">
<cfinvoke component = "#cfcname#" method = "#method#" argumentCollection = "#args#"
returnVariable = "resultval">
<cflog text="onRESTRequest() After">
<cfreturn "#resultval#">
</cffunction>
45
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Remote not needed any more
component output="false" rest="true" restpath="/sample"
{
remote numeric function add(required numeric a restargsource="query", required numeric b
restargsource="query")
output="false" produces="application/json" httpmethod="get"
{
return a + b;
}
remote numeric function substract(required numeric a restargsource="query", required numeric b
restargsource="query")
output="false" produces="application/json" restpath="/sub" httpmethod="get" {
return a - b;
}
}
46
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
REST Enhancements
47
Configurable REST Servlet Path
from ColdFusion administrator
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Language Enhancement
<cfscript>
a = structnew();
a["sample"] = true;
a["lastname"] = "no";
a["firstname"] = "firstname";
a["value"] = "10.256";
writeoutput(serializejson(a));
</cfscript>
48
Expected Result:
{
"lastname": "no",
"sample": true,
"firstname": "firstname",
"value": "10.256"
}
Actual Result:
{
"lastname": false,
"sample": true,
"firstname": "firstname",
"value": 10.256
}
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Language Enhancement (Literal Type Preservation)
 ColdFusion does not preserve the literal type.
 All the literals are stored as String By default
 Based on the context the string literal is converted to the desired type
How to change this ?
 JVM Flag coldfusion.literal.preservetype (by default false) set it to true
 Setting it true preserves the literals using respective data type.
 Requires recompilation of the templates (clear cache)
 Few backward compatibility issues exists.
49
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Conclusion
 Many hassles removed
 Smooth Development Workflow
 Easy Testing with Swagger and RESTPlay
 New REST Enhancements
https://github.com/sunnypav/cfsummit2017_rest
50
© 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 51
REST Development made Easy with ColdFusion Aether

More Related Content

PDF
Migration to ColdFusion 11 – making it seamless and easy anit
PDF
Developing html5 mobile applications using cold fusion 11
PDF
Hidden Gems in ColdFusion 2016
PPTX
10 Reasons ColdFusion PDFs should rule the world
PDF
Api manager preconference
PPTX
Mobile Apps with ColdFusion
PDF
Using eZ Platform in an API Era
PDF
Where is cold fusion headed
Migration to ColdFusion 11 – making it seamless and easy anit
Developing html5 mobile applications using cold fusion 11
Hidden Gems in ColdFusion 2016
10 Reasons ColdFusion PDFs should rule the world
Api manager preconference
Mobile Apps with ColdFusion
Using eZ Platform in an API Era
Where is cold fusion headed

What's hot (20)

PDF
Command Box ColdFusion Package Manager, Automation
PPT
Restful API's with ColdFusion
PPTX
Workflows and Digital Signatures
PDF
Developer Insights for Application Upgrade to ColdFusion 2016
PPTX
PHP and Platform Independance in the Cloud
PPTX
ColdFusion 11 Overview - CFSummit 2013
PPTX
Load Balancing, Failover and Scalability with ColdFusion
PDF
In The Trenches With Tomster, Upgrading Ember.js & Ember Data
PPTX
Demystify Salesforce Bulk API
PDF
Securing applications
PPTX
Automating Enterprise Application Deployments with PowerShell
PPTX
Extra aem development tools by Justin Edelson
PDF
Understanding and testing restful web services
PDF
Have Some Rest Building Web2.0 Apps And Services
PDF
Bring api manager into your stack
PDF
RIAs with Java, Spring, Hibernate, BlazeDS, and Flex
PDF
Asp.Net Core MVC , Razor page , Entity Framework Core
ODP
Java Tech & Tools | OSGi Best Practices | Emily Jiang
PDF
WordCamp Raleigh 2016 - WP API, What is it good for? Absolutely Everything!
PDF
Serverless Media Workflow
Command Box ColdFusion Package Manager, Automation
Restful API's with ColdFusion
Workflows and Digital Signatures
Developer Insights for Application Upgrade to ColdFusion 2016
PHP and Platform Independance in the Cloud
ColdFusion 11 Overview - CFSummit 2013
Load Balancing, Failover and Scalability with ColdFusion
In The Trenches With Tomster, Upgrading Ember.js & Ember Data
Demystify Salesforce Bulk API
Securing applications
Automating Enterprise Application Deployments with PowerShell
Extra aem development tools by Justin Edelson
Understanding and testing restful web services
Have Some Rest Building Web2.0 Apps And Services
Bring api manager into your stack
RIAs with Java, Spring, Hibernate, BlazeDS, and Flex
Asp.Net Core MVC , Razor page , Entity Framework Core
Java Tech & Tools | OSGi Best Practices | Emily Jiang
WordCamp Raleigh 2016 - WP API, What is it good for? Absolutely Everything!
Serverless Media Workflow
Ad

Similar to REST Development made Easy with ColdFusion Aether (20)

PPTX
ColdFusion Internals
PDF
ColdFusion 10
PPTX
Keeping Current with ColdFusion - Adobe Max 2011
PPT
Restful services with ColdFusion
PDF
This is how we REST
PDF
How we REST
PDF
PDF
CFWheels - Pragmatic, Beautiful Code
PDF
API management with Taffy and API Blueprint
PDF
RESTful applications: The why and how by Maikel Mardjan
PDF
Architecting for scalability in cf
PDF
Accessing ColdFusion Services From Flex Applications
PPTX
Building Software Backend (Web API)
PDF
REST full API Design
PDF
Api FUNdamentals #MHA2017
PPTX
RESTful API Design: Illustrated
PDF
EVOLVE'13 | Keynote | Roy Fielding
PDF
EVOLVE`13 Keynote: Scrambled Eggs
PPTX
Everyday life with Cloud Foundry in a big organization (Cloud Foundry Days To...
PPSX
Restful web services rule financial
ColdFusion Internals
ColdFusion 10
Keeping Current with ColdFusion - Adobe Max 2011
Restful services with ColdFusion
This is how we REST
How we REST
CFWheels - Pragmatic, Beautiful Code
API management with Taffy and API Blueprint
RESTful applications: The why and how by Maikel Mardjan
Architecting for scalability in cf
Accessing ColdFusion Services From Flex Applications
Building Software Backend (Web API)
REST full API Design
Api FUNdamentals #MHA2017
RESTful API Design: Illustrated
EVOLVE'13 | Keynote | Roy Fielding
EVOLVE`13 Keynote: Scrambled Eggs
Everyday life with Cloud Foundry in a big organization (Cloud Foundry Days To...
Restful web services rule financial
Ad

Recently uploaded (20)

PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PDF
Hindi spoken digit analysis for native and non-native speakers
PDF
STKI Israel Market Study 2025 version august
PPTX
The various Industrial Revolutions .pptx
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Getting Started with Data Integration: FME Form 101
PDF
Zenith AI: Advanced Artificial Intelligence
PPT
Module 1.ppt Iot fundamentals and Architecture
PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
WOOl fibre morphology and structure.pdf for textiles
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PDF
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
CloudStack 4.21: First Look Webinar slides
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PDF
DP Operators-handbook-extract for the Mautical Institute
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Final SEM Unit 1 for mit wpu at pune .pptx
Hindi spoken digit analysis for native and non-native speakers
STKI Israel Market Study 2025 version august
The various Industrial Revolutions .pptx
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
Assigned Numbers - 2025 - Bluetooth® Document
Getting Started with Data Integration: FME Form 101
Zenith AI: Advanced Artificial Intelligence
Module 1.ppt Iot fundamentals and Architecture
A novel scalable deep ensemble learning framework for big data classification...
WOOl fibre morphology and structure.pdf for textiles
NewMind AI Weekly Chronicles – August ’25 Week III
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
Group 1 Presentation -Planning and Decision Making .pptx
CloudStack 4.21: First Look Webinar slides
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
DP Operators-handbook-extract for the Mautical Institute

REST Development made Easy with ColdFusion Aether

  • 1. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. REST Development made Easy with ColdFusion Aether S V Pavan Kumar | [email protected]
  • 2. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. About Pavan 2 Adobe ColdFusion & API Manager Product Team Security Czar for ColdFusion Team Experienced Java Developer Former Developer at RSA Security Stewie: What kind of feet can fit into these shoes?!  Brian: YOUR FEET!
  • 3. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 3 ColdFusion Aether
  • 4. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Agenda  Writing a Simple Rest Service using CF  Development Workflow Issues  What’s new  Demo 4
  • 5. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Simple CFC component output="false" { public Book function deletebook(required numeric bookid) description="Deletes Specified Book"{ // Function Body } public any function getAllBooks() description="Gets list of all Books" { // Function Body } public Book function getBook(required numeric bookid) description="Get Book by ID" { // Function Body } public numeric function addBook(required struct newbook) description="Add a new book" { // Function Body Err: why can’t I use Book CFC as input argument type instead of struct } } 5
  • 6. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. REST  REST is about resources and how to represent them in different ways  REST is about how to manipulate resources  It’s a architectural style  Representational state transfer  It runs on existing standard Http protocol Methods (GET, PUT, POST, DELETE, PATCH) HTTP URI Syntax (PATHs, parameters etc.) Media Types (xml, json, html. text etc.) HTTP response codes  ColdFusion offers simple and flexible way of writing REST Web services 6
  • 7. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. REST API http://service.com/rest/dw/books http://service.com/rest/dw/books/{id } GET http://service.com/rest/dw/books HTTP/1. POST http://service.com/rest/dw/books/123 HTTP/1.1 DELETE http://service.com/rest/dw/books/123 HTTP/1.1 <books> <book id="123",name="Harry Porter"> <author>JK Rowling</author> </book> </books> { "books":{[{"book":{ "author“ : "JK Rowling", "id“ : 123 "name“ : "Harry Porter" } }]} } 7
  • 8. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. CFC as Resource component restpath="books" rest="true" output="false" { // Component Body } 8
  • 9. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Function -> REST public any function getAllBooks() description="Gets all Books“ httpmethod="GET" produces= "application/json,application/xml" { // Function Body } 9
  • 10. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. How the URL is Formed 10 http(s)://<hostname>:[port]/servlet mapping/service mapping/[cfcrestpath]/[methodrestpath]
  • 11. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Function -> REST public numeric function addBook(required struct newbook restargsource="body") description="Add a new book“ consumes="application/json" produces="text/plain" httpmethod="POST" { } 11
  • 12. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. CFArgument public Book function getBook(required numeric bookid restargsource = "path" restargname="bookid") description="Get Book by ID“ restpath="{bookid}" produces="application/json" httpmethod="GET" { // Function Body } 12 http://localhost:8500/rest/dw/books/20 Componentbookid
  • 13. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Registering REST application  Register the directory containing the REST service in following ways:  ColdFusion Administrative Console  ColdFusion Admin API  Using restInitApplication 13
  • 14. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Registering REST application 2.) Admin API : One requires Admin privilege to invoke below functions  registerRESTService(rootPath, [service mapping])  getRESTServices() : returns array of REST services registered with ColdFusion  deleteRESTService(rootPath): Deletes REST service at the specified path  refreshRESTService(rootPath): If you make any changes to the REST-enabled CF component, you can refresh the registered application by calling this function. 3.) restInitApplication(rootPath,[serviceMapping]) 4.) 14 <cfset this.restsettings.autoregister="true"/>
  • 15. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Development Issues 15
  • 16. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. REST Developer Problems 16
  • 17. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. REST Developer Problems 17
  • 18. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. REST Developer Problems 18
  • 19. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. REST Developer Problems 19
  • 20. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. REST Developer Problems 20
  • 21. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. REST Developer Problems 21  Difficulty in exploring the REST URLs (Going through CFCs to derive them)  http://localhost:8500/rest/servicemapping/shopping/itemcode  URL has 4 parts – deriving it is a cumbersome work
  • 22. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. REST Developer Problems 22
  • 23. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. REST Developer Problems (Swagger) 23 Root Swagger: http(s)://<hostname>:[port]/servlet mapping/service mapping/api-docs Resource Level Swagger: http(s)://<hostname>:[port]/servlet mapping/service mapping/api-docs/resource-name
  • 24. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. REST Developer Problems  For every change in code developer is forced to login to the ColdFusion Administrator and refresh the server to test them  Debugging the Runtime errors used to be difficult  Digging through the large log files and associating that to the current context used to be difficult every time.  Not showing the compilation errors in the admin UI 24
  • 25. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. REST Developer Problems  Difficulty in exploring the REST URLs (Going through CFCs to derive them)  Manually interpreting the Swagger Docs  No Quick Testing tools  Gaps in REST Language 25
  • 26. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Categories of Enhancements  REST Development friendly Enhancements  REST Language Enhancements 26
  • 27. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Developer Profile 27
  • 28. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. REST Development (Developer Friendly)  REST services made dynamic Pros: -No more refreshes to reflect the changed code -The behaviour synonymous with normal ColdFusion development Cons: - Auto-refresh adds some time lag. - For production environments user can turn-off this feature. 28
  • 29. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Tools making REST development faster  RESTPlay application.  No login required - Just Enable Developer profile  Auto listing of the applications and URLs in the app.  Swagger docs are integrated http://localhost:8500/restplay 29
  • 30. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. RESTPlay Application  Showing the error stack trace now on-the-go  Show the Compilation errors while registering the application. 30
  • 31. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. RESTPlay Application-How it eases 31
  • 32. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. RESTPlay Application-How it eases 32
  • 33. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. RESTPlay Application-How it eases 33
  • 34. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. RESTPlay  From RESTPlay app even in production REST services can be tested(Precondition-URL should be known) Ex:- http://localhost:8500/rest/mapping/shopping/restplay 34
  • 35. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. REST Enhancements  REST Language Enhancements 35
  • 36. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. REST Enhancements (Language)  Support for REST Functions with Component(Bean) as arguments remote any function setuserPost(student x) httpmethod="POST" restpath="setuser" description="Setuser using POST" { return x; } { "name": "pavan kumar", "company": "Adobe Systems" } 36
  • 37. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. REST Enhancements  Support for JSON Patch (rfc6902) User can submit only the fields that they want to update instead of submitting the whole object. Request becomes thin. https://sookocheff.com/post/api/understanding-json-patch/ 37
  • 38. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. JSON Patch 38 Original: { "baz": "qux", "foo": "bar" } Patch: [ { "op": "replace", "path": "/baz", "value": "boo" }, { "op": "add", "path": "/hello", "value": ["world"] }, { "op": "remove", "path": "/foo"} ] { "baz": "boo", "hello": ["world"] }
  • 39. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. REST Enhancements 39
  • 40. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. REST Enhancements 40
  • 41. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. REST Enhancements 41
  • 42. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. REST Enhancements  Entity Filtering support(JSON Field Projection) User can opt to receive the fields that are of his interest in the response. Response becomes thin 42
  • 43. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. REST Enhancements 43
  • 44. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. REST Enhancements  Enhanced restSetResponse() User can set the response even when the function's return type is non-void. 44
  • 45. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. REST Enhancements  Support for onRESTRequest life cycle function (Equivalent of onCFCRequest) - Works as an interceptor to the REST Calls (User can use it for logging/adding security layer) <cffunction name="onRESTRequest" returntype="any" output="true"> <cfargument type="string" name="cfcname" required=true> <cfargument type="string" name="method" required=true> <cfargument type="struct" name="args" required=true> <cflog text="onRESTRequest() Before"> <cfinvoke component = "#cfcname#" method = "#method#" argumentCollection = "#args#" returnVariable = "resultval"> <cflog text="onRESTRequest() After"> <cfreturn "#resultval#"> </cffunction> 45
  • 46. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Remote not needed any more component output="false" rest="true" restpath="/sample" { remote numeric function add(required numeric a restargsource="query", required numeric b restargsource="query") output="false" produces="application/json" httpmethod="get" { return a + b; } remote numeric function substract(required numeric a restargsource="query", required numeric b restargsource="query") output="false" produces="application/json" restpath="/sub" httpmethod="get" { return a - b; } } 46
  • 47. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. REST Enhancements 47 Configurable REST Servlet Path from ColdFusion administrator
  • 48. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Language Enhancement <cfscript> a = structnew(); a["sample"] = true; a["lastname"] = "no"; a["firstname"] = "firstname"; a["value"] = "10.256"; writeoutput(serializejson(a)); </cfscript> 48 Expected Result: { "lastname": "no", "sample": true, "firstname": "firstname", "value": "10.256" } Actual Result: { "lastname": false, "sample": true, "firstname": "firstname", "value": 10.256 }
  • 49. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Language Enhancement (Literal Type Preservation)  ColdFusion does not preserve the literal type.  All the literals are stored as String By default  Based on the context the string literal is converted to the desired type How to change this ?  JVM Flag coldfusion.literal.preservetype (by default false) set it to true  Setting it true preserves the literals using respective data type.  Requires recompilation of the templates (clear cache)  Few backward compatibility issues exists. 49
  • 50. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Conclusion  Many hassles removed  Smooth Development Workflow  Easy Testing with Swagger and RESTPlay  New REST Enhancements https://github.com/sunnypav/cfsummit2017_rest 50
  • 51. © 2017 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 51

Editor's Notes

  • #38: The typical update cycle for an API resource is to (1) GET the representation, (2) modify it and (3) PUT back the entire representation. This can waste bandwidth and processing time for large resources. An alternative is to use the HTTP PATCH extension method to only send the differences between two resources. HTTP PATCH applies a set of changes to the document referenced by the HTTP request.
  • #49: The ColdFusion language is typeless and does not evaluate or preserve the type information at the time of code generation. At runtime, ColdFusion tries to make its best guess to determine the datatype, which may cause some unexpected behavior. For example, at the time of JSON serialization, ColdFusion attempts at converting a string to a number. If the attempt is successful, then the passed data type is treated as number irrespective of whether you wanted it to be a string or not.