SlideShare a Scribd company logo
1 of 35
By Acellam Guy
@mistaguy
1. Consume JSON REST based services
2. Publish data or microflows through REST API's
3. (Real time) Synchronization of data between Mendix
applications
By Acellam Guy
@mistaguy
REST ?
• REST stands for Representational StateTransfer
• BuildWeb services that are lightweight, maintainable, and scalable
• A service based on REST is called a RESTful service
• REST is not dependent on any protocol
By Acellam Guy
@mistaguy
Features of a RESTful webservice
• Representations
• Messages
• URIs
• Uniform interface
• Stateless
• Links between resources
• Caching
By Acellam Guy
@mistaguy
Representations
• Resources and how to provide access to these resources
• Format of representation JSON,XML ,etc
• Both client and server should be able to comprehend format of
representation
• A representation should be able to completely represent a resource
• The representation should be capable of linking resources to each other
By Acellam Guy
@mistaguy
Messages
• Contains the actual data and metadata about the message
• Based on HTTP 1.1
By Acellam Guy
@mistaguy
URI
• The job of a URI is to identify a resource or a collection of resources
• The actual operation is determined by an HTTP verb
Eg.
http://localhost:8080/Persons/1
This URL has following
format: Protocol://ServiceName/ResourceType/ResourceID
By Acellam Guy
@mistaguy
Uniform Interface
• Systems should have a uniform interface. HTTP 1.1 provides a set of
methods, called verbs, for this purpose
Method Operation performed on server Quality
GET Read a resource. Safe
PUT Insert a new resource or update if the resource already exists. Idempotent
POST Insert a new resource. Also can be used to update an existing resource. N/A
DELETE Delete a resource . Idempotent
OPTIONS List the allowed operations on a resource. Safe
HEAD Return only the response headers and no response body. Safe
By Acellam Guy
@mistaguy
Statelessness
• Does not maintain the application state for any client
• A request cannot be dependent on a past request and a service treats each
request independently
A stateless design looks like so:
Request1: GET http://MyService/Persons/1 HTTP/1.1
Request2: GET http://MyService/Persons/2 HTTP/1.1
Each of these requests can be treated separately.
A stateful design, on the other hand, looks like so:
Request1: GET http://MyService/Persons/1 HTTP/1.1
Request2: GET http://MyService/NextPerson HTTP/1.1
By Acellam Guy
@mistaguy
Links Between Resources
• A resource representation can contain links to other resources like an HTML
page contains links to other pages
• The user does not need a map before coming to a website
• A service can be (and should be) designed in the same way
By Acellam Guy
@mistaguy
Caching
• Caching is the concept of storing the generated results and using the stored
results instead of generating them repeatedly if the same request arrives in
the near future
By Acellam Guy
@mistaguy
Mendix REST Module
• Mendix 4.4.4+ or Mendix 5.3.1+
• If you want to publish REST services or use the data synchronization features,
addIVK_OpenServiceOverview to your main navigation.
add StartPublishServices to the startup sequence of your application
• map your administrative project role to the Administratorrole in the RestServices
for admin features
• The 'rest/' request handler needs to be opened if running in the Mendix Standard
Cloud (or on premise).
• strongly recommended to not use the default HSQLDB engine if you want to
publish RestServices while running locally
By Acellam Guy
@mistaguy
Consuming REST services
• The operations in the 'Consume' folder of the module provide the necessary
tools to invoke data
• The core of all these operations is the java action request
By Acellam Guy
@mistaguy
The REQUEST java action
• Request performs an HTTP request and provides the means to both send data and receive
data over HTTP
• Parameters
• Method : HTTP 1.1 verbs
• URL : location of the service
• optRequestData : provides parameters
• optResponseData : provides response
• ResquestResult : HTTP response
• sendWithFormEncoding
By Acellam Guy
@mistaguy
RequestResult Object
• contains the meta information of a response
• Response code
• Etag
• ResponseBody :the full and raw response body of the request.
By Acellam Guy
@mistaguy
Sending Request Headers
• addHeaderToNextRequest : will add a header to the next (and only the next)
request that will be made by the current microflow
By Acellam Guy
@mistaguy
Authentication
• Only supports Basic authentication out of the box
• Other authentication mechanism such as Oauth can be integrated
By Acellam Guy
@mistaguy
Consume Methods
• get :Tries to retrieve an object from the provided resourceURL
• get2: Similar to get, but also accepts a requestData parameter
• ?q=Rest%20Services‘
• getCollection : gets a list of objects. JSON array
• getCollectionAsync
• post
• delete
• put
• getRequestConsumerError
By Acellam Guy
@mistaguy
Template URLS
• This makes it possible to substitute values directly in an URL
By Acellam Guy
@mistaguy
Publishing webservices
• Publishing operations, based on a single microflow.
• Publishing a part of your data model, and providing a typical rest based API
to retrieve, update, delete, create and even real-time sync data.
• PLEASE NOTETHATTO BE ABLETO PUBLISH ANY SERVICE,THE
MICROFLOW STARTPUBLISHSERVICES SHOULD BE CALLED DURING
STARTUP OFTHE APP!
• Accessible via http://apphost/rest/yourservice
By Acellam Guy
@mistaguy
Publishing a microflow
• similar to publishing a webservice
• instead of SOAP it uses JSON based messages
• Has a single transient object as argument.
• Each field in this transient object is considered a parameter (from HTTP perspective)
• The return type of the microflow should be a transient object or a String or a filedocument
• Publish by calling CreateMicroflowService with the microflow that provides the
implementation
By Acellam Guy
@mistaguy
Microflow with template path
• Allows for constructing more complex URLs, from which values are parsed
Eg.
groups/{groupId}/users/{userId}
http://myapp.com/rest/groups/123/users/John
By Acellam Guy
@mistaguy
Publishing a data service
• JSON based API to list, retrieve, create, update, delete and track objects in
your database
• Documentation is generated automatically
By Acellam Guy
@mistaguy
End points on the service
By Acellam Guy
@mistaguy
How the data service works
• persistent entity in your database acting as data source
• transient object that acts as view object of your data
• Publish Microflow has the responsibility of converting source objects into
view objects
• Update Microflow is responsible for transforming a view as provided by
some consumer into real data in your database
• Each source object should be uniquely identifiable by a single key attribute
By Acellam Guy
@mistaguy
Example
• GET <your-app>/rest/<service name>/<identifier>
By Acellam Guy
@mistaguy
Creating a new webservice
• Add IVK_OpenServiceOverview to your navigation and create a new
Published Service after starting your app
• best practice is to use the GetOrCreateDataService microflow in the
startup microflow to create your service configuration
By Acellam Guy
@mistaguy
Configuring the service
• Its done on the form or the create service microflow
• Core configuration are:
• Name
• Description
• Source Entity
• Source Key Attribute
• Source Constraint : xpath
• Authentication Role
• On Publish Microflow
• On Update Microflow
• On Delete Microflow
By Acellam Guy
@mistaguy
Features
• Enable GET : HTTP GET
• Enable Listing : HTTP GET
• Enable Update : HTTP POST or PUT
• Enable Create : HTTP POST
• Enable Delete : HTTP DELETE
• Enable Change Log: caching
• Enable StrictVersion:
By Acellam Guy
@mistaguy
Securing Published webservice
• *
• Rolename
• Module.Microflowname : Authentication details found in the header eg key
By Acellam Guy
@mistaguy
JSON Serialization
• Converts transient object to JSON
• Nearest json type
• For each owned reference that points to a transient object, another
key/value pair is added to the object
• For each owned referenceset that points to a transient object, the same
approach is taken, except that the value is an array ([])
• Manual serialization process by use of serializeObjectToJson java action.
By Acellam Guy
@mistaguy
By Acellam Guy
@mistaguy
JSON Desrialization
• an be triggered manually by calling deserializeJsonToObject
• Converts the json from the consumer into a mendix transient object
• key/value pair for primitive attribute in transient object
• If the primitive is of type string, but the member with the same name in the
transient object is a reference, the process assumes that the string value represents
an url.
• If the member in the target object is a reference, and the value is a JSON object, a
new object of the child type of the reference is instantiated
• If target is reference set and JSON is array then reference set is created
By Acellam Guy
@mistaguy
By Acellam Guy
@mistaguy
Assignment
• Consume the twitter rest API and show the recent tweets for your profile
By Acellam Guy
@mistaguy
References
• http://www.drdobbs.com/web-development/restful-web-services-a-
tutorial/240169069
• https://github.com/mendix/RestServices

More Related Content

What's hot

MuleSoft: How to Engage Partners/Customers and API Led with Alexa
MuleSoft: How to Engage Partners/Customers and  API Led with Alexa MuleSoft: How to Engage Partners/Customers and  API Led with Alexa
MuleSoft: How to Engage Partners/Customers and API Led with Alexa
Angel Alberici
 

What's hot (20)

Google app engine
Google app engineGoogle app engine
Google app engine
 
Microservices Architecture - Bangkok 2018
Microservices Architecture - Bangkok 2018Microservices Architecture - Bangkok 2018
Microservices Architecture - Bangkok 2018
 
MuleSoft: How to Engage Partners/Customers and API Led with Alexa
MuleSoft: How to Engage Partners/Customers and  API Led with Alexa MuleSoft: How to Engage Partners/Customers and  API Led with Alexa
MuleSoft: How to Engage Partners/Customers and API Led with Alexa
 
Cloud Migration Strategy and Best Practices
Cloud Migration Strategy and Best PracticesCloud Migration Strategy and Best Practices
Cloud Migration Strategy and Best Practices
 
Design patterns for microservice architecture
Design patterns for microservice architectureDesign patterns for microservice architecture
Design patterns for microservice architecture
 
2022-04 VMware DevOps Loop.pptx.pdf
2022-04 VMware DevOps Loop.pptx.pdf2022-04 VMware DevOps Loop.pptx.pdf
2022-04 VMware DevOps Loop.pptx.pdf
 
Mendix Platform
Mendix PlatformMendix Platform
Mendix Platform
 
Api Gateway
Api GatewayApi Gateway
Api Gateway
 
Serverless Computing: build and run applications without thinking about servers
Serverless Computing: build and run applications without thinking about serversServerless Computing: build and run applications without thinking about servers
Serverless Computing: build and run applications without thinking about servers
 
Google cloud platform
Google cloud platformGoogle cloud platform
Google cloud platform
 
Capgemini Cloud Assessment - A Pathway to Enterprise Cloud Migration
Capgemini Cloud Assessment - A Pathway to Enterprise Cloud MigrationCapgemini Cloud Assessment - A Pathway to Enterprise Cloud Migration
Capgemini Cloud Assessment - A Pathway to Enterprise Cloud Migration
 
02 api gateway
02 api gateway02 api gateway
02 api gateway
 
App Modernization with Microsoft Azure
App Modernization with Microsoft AzureApp Modernization with Microsoft Azure
App Modernization with Microsoft Azure
 
AWS Cloud Assessment
AWS Cloud AssessmentAWS Cloud Assessment
AWS Cloud Assessment
 
API Gateway Use Cases​ for Kubernetes​
API Gateway Use Cases​ for Kubernetes​API Gateway Use Cases​ for Kubernetes​
API Gateway Use Cases​ for Kubernetes​
 
DevOps Monitoring and Alerting
DevOps Monitoring and AlertingDevOps Monitoring and Alerting
DevOps Monitoring and Alerting
 
Devops Strategy Roadmap Lifecycle Ppt Powerpoint Presentation Slides Complete...
Devops Strategy Roadmap Lifecycle Ppt Powerpoint Presentation Slides Complete...Devops Strategy Roadmap Lifecycle Ppt Powerpoint Presentation Slides Complete...
Devops Strategy Roadmap Lifecycle Ppt Powerpoint Presentation Slides Complete...
 
What do you mean by “API as a Product”?
What do you mean by “API as a Product”?What do you mean by “API as a Product”?
What do you mean by “API as a Product”?
 
Why Microservice
Why Microservice Why Microservice
Why Microservice
 
Managed Test Services - Maveric Systems
Managed Test Services - Maveric SystemsManaged Test Services - Maveric Systems
Managed Test Services - Maveric Systems
 

Similar to Mendix rest services

J2EE : Java servlet and its types, environment
J2EE : Java servlet and its types, environmentJ2EE : Java servlet and its types, environment
J2EE : Java servlet and its types, environment
joearunraja2
 

Similar to Mendix rest services (20)

J2EE : Java servlet and its types, environment
J2EE : Java servlet and its types, environmentJ2EE : Java servlet and its types, environment
J2EE : Java servlet and its types, environment
 
CNIT 128: 6: Mobile services and mobile Web (part 1: Beginning Through OAuth)
CNIT 128: 6: Mobile services and mobile Web (part 1: Beginning Through OAuth)CNIT 128: 6: Mobile services and mobile Web (part 1: Beginning Through OAuth)
CNIT 128: 6: Mobile services and mobile Web (part 1: Beginning Through OAuth)
 
BITM3730 11-1.pptx
BITM3730 11-1.pptxBITM3730 11-1.pptx
BITM3730 11-1.pptx
 
BITM3730 Networking.pdf
BITM3730 Networking.pdfBITM3730 Networking.pdf
BITM3730 Networking.pdf
 
Windows 8 Metro apps and the outside world
Windows 8 Metro apps and the outside worldWindows 8 Metro apps and the outside world
Windows 8 Metro apps and the outside world
 
REST Methodologies
REST MethodologiesREST Methodologies
REST Methodologies
 
web connectivity in IoT
web connectivity in IoTweb connectivity in IoT
web connectivity in IoT
 
Windows 8 Apps and the Outside World
Windows 8 Apps and the Outside WorldWindows 8 Apps and the Outside World
Windows 8 Apps and the Outside World
 
BeJUG JAX-RS Event
BeJUG JAX-RS EventBeJUG JAX-RS Event
BeJUG JAX-RS Event
 
Rest
Rest Rest
Rest
 
AJAX.pptx
AJAX.pptxAJAX.pptx
AJAX.pptx
 
Browser
BrowserBrowser
Browser
 
IT2255 Web Essentials - Unit V Servlets and Database Connectivity
IT2255 Web Essentials - Unit V Servlets and Database ConnectivityIT2255 Web Essentials - Unit V Servlets and Database Connectivity
IT2255 Web Essentials - Unit V Servlets and Database Connectivity
 
SCWCD : The web client model
SCWCD : The web client modelSCWCD : The web client model
SCWCD : The web client model
 
rest-api-basics.pptx
rest-api-basics.pptxrest-api-basics.pptx
rest-api-basics.pptx
 
Lecture 2: Servlets
Lecture 2:  ServletsLecture 2:  Servlets
Lecture 2: Servlets
 
restapitest-anil-200517181251.pdf
restapitest-anil-200517181251.pdfrestapitest-anil-200517181251.pdf
restapitest-anil-200517181251.pdf
 
Rest API Testing
Rest API TestingRest API Testing
Rest API Testing
 
REST Basics
REST BasicsREST Basics
REST Basics
 
Rest APIs Training
Rest APIs TrainingRest APIs Training
Rest APIs Training
 

Recently uploaded

%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 

Recently uploaded (20)

Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 

Mendix rest services

  • 1. By Acellam Guy @mistaguy 1. Consume JSON REST based services 2. Publish data or microflows through REST API's 3. (Real time) Synchronization of data between Mendix applications
  • 2. By Acellam Guy @mistaguy REST ? • REST stands for Representational StateTransfer • BuildWeb services that are lightweight, maintainable, and scalable • A service based on REST is called a RESTful service • REST is not dependent on any protocol
  • 3. By Acellam Guy @mistaguy Features of a RESTful webservice • Representations • Messages • URIs • Uniform interface • Stateless • Links between resources • Caching
  • 4. By Acellam Guy @mistaguy Representations • Resources and how to provide access to these resources • Format of representation JSON,XML ,etc • Both client and server should be able to comprehend format of representation • A representation should be able to completely represent a resource • The representation should be capable of linking resources to each other
  • 5. By Acellam Guy @mistaguy Messages • Contains the actual data and metadata about the message • Based on HTTP 1.1
  • 6. By Acellam Guy @mistaguy URI • The job of a URI is to identify a resource or a collection of resources • The actual operation is determined by an HTTP verb Eg. http://localhost:8080/Persons/1 This URL has following format: Protocol://ServiceName/ResourceType/ResourceID
  • 7. By Acellam Guy @mistaguy Uniform Interface • Systems should have a uniform interface. HTTP 1.1 provides a set of methods, called verbs, for this purpose Method Operation performed on server Quality GET Read a resource. Safe PUT Insert a new resource or update if the resource already exists. Idempotent POST Insert a new resource. Also can be used to update an existing resource. N/A DELETE Delete a resource . Idempotent OPTIONS List the allowed operations on a resource. Safe HEAD Return only the response headers and no response body. Safe
  • 8. By Acellam Guy @mistaguy Statelessness • Does not maintain the application state for any client • A request cannot be dependent on a past request and a service treats each request independently A stateless design looks like so: Request1: GET http://MyService/Persons/1 HTTP/1.1 Request2: GET http://MyService/Persons/2 HTTP/1.1 Each of these requests can be treated separately. A stateful design, on the other hand, looks like so: Request1: GET http://MyService/Persons/1 HTTP/1.1 Request2: GET http://MyService/NextPerson HTTP/1.1
  • 9. By Acellam Guy @mistaguy Links Between Resources • A resource representation can contain links to other resources like an HTML page contains links to other pages • The user does not need a map before coming to a website • A service can be (and should be) designed in the same way
  • 10. By Acellam Guy @mistaguy Caching • Caching is the concept of storing the generated results and using the stored results instead of generating them repeatedly if the same request arrives in the near future
  • 11. By Acellam Guy @mistaguy Mendix REST Module • Mendix 4.4.4+ or Mendix 5.3.1+ • If you want to publish REST services or use the data synchronization features, addIVK_OpenServiceOverview to your main navigation. add StartPublishServices to the startup sequence of your application • map your administrative project role to the Administratorrole in the RestServices for admin features • The 'rest/' request handler needs to be opened if running in the Mendix Standard Cloud (or on premise). • strongly recommended to not use the default HSQLDB engine if you want to publish RestServices while running locally
  • 12. By Acellam Guy @mistaguy Consuming REST services • The operations in the 'Consume' folder of the module provide the necessary tools to invoke data • The core of all these operations is the java action request
  • 13. By Acellam Guy @mistaguy The REQUEST java action • Request performs an HTTP request and provides the means to both send data and receive data over HTTP • Parameters • Method : HTTP 1.1 verbs • URL : location of the service • optRequestData : provides parameters • optResponseData : provides response • ResquestResult : HTTP response • sendWithFormEncoding
  • 14. By Acellam Guy @mistaguy RequestResult Object • contains the meta information of a response • Response code • Etag • ResponseBody :the full and raw response body of the request.
  • 15. By Acellam Guy @mistaguy Sending Request Headers • addHeaderToNextRequest : will add a header to the next (and only the next) request that will be made by the current microflow
  • 16. By Acellam Guy @mistaguy Authentication • Only supports Basic authentication out of the box • Other authentication mechanism such as Oauth can be integrated
  • 17. By Acellam Guy @mistaguy Consume Methods • get :Tries to retrieve an object from the provided resourceURL • get2: Similar to get, but also accepts a requestData parameter • ?q=Rest%20Services‘ • getCollection : gets a list of objects. JSON array • getCollectionAsync • post • delete • put • getRequestConsumerError
  • 18. By Acellam Guy @mistaguy Template URLS • This makes it possible to substitute values directly in an URL
  • 19. By Acellam Guy @mistaguy Publishing webservices • Publishing operations, based on a single microflow. • Publishing a part of your data model, and providing a typical rest based API to retrieve, update, delete, create and even real-time sync data. • PLEASE NOTETHATTO BE ABLETO PUBLISH ANY SERVICE,THE MICROFLOW STARTPUBLISHSERVICES SHOULD BE CALLED DURING STARTUP OFTHE APP! • Accessible via http://apphost/rest/yourservice
  • 20. By Acellam Guy @mistaguy Publishing a microflow • similar to publishing a webservice • instead of SOAP it uses JSON based messages • Has a single transient object as argument. • Each field in this transient object is considered a parameter (from HTTP perspective) • The return type of the microflow should be a transient object or a String or a filedocument • Publish by calling CreateMicroflowService with the microflow that provides the implementation
  • 21. By Acellam Guy @mistaguy Microflow with template path • Allows for constructing more complex URLs, from which values are parsed Eg. groups/{groupId}/users/{userId} http://myapp.com/rest/groups/123/users/John
  • 22. By Acellam Guy @mistaguy Publishing a data service • JSON based API to list, retrieve, create, update, delete and track objects in your database • Documentation is generated automatically
  • 23. By Acellam Guy @mistaguy End points on the service
  • 24. By Acellam Guy @mistaguy How the data service works • persistent entity in your database acting as data source • transient object that acts as view object of your data • Publish Microflow has the responsibility of converting source objects into view objects • Update Microflow is responsible for transforming a view as provided by some consumer into real data in your database • Each source object should be uniquely identifiable by a single key attribute
  • 25. By Acellam Guy @mistaguy Example • GET <your-app>/rest/<service name>/<identifier>
  • 26. By Acellam Guy @mistaguy Creating a new webservice • Add IVK_OpenServiceOverview to your navigation and create a new Published Service after starting your app • best practice is to use the GetOrCreateDataService microflow in the startup microflow to create your service configuration
  • 27. By Acellam Guy @mistaguy Configuring the service • Its done on the form or the create service microflow • Core configuration are: • Name • Description • Source Entity • Source Key Attribute • Source Constraint : xpath • Authentication Role • On Publish Microflow • On Update Microflow • On Delete Microflow
  • 28. By Acellam Guy @mistaguy Features • Enable GET : HTTP GET • Enable Listing : HTTP GET • Enable Update : HTTP POST or PUT • Enable Create : HTTP POST • Enable Delete : HTTP DELETE • Enable Change Log: caching • Enable StrictVersion:
  • 29. By Acellam Guy @mistaguy Securing Published webservice • * • Rolename • Module.Microflowname : Authentication details found in the header eg key
  • 30. By Acellam Guy @mistaguy JSON Serialization • Converts transient object to JSON • Nearest json type • For each owned reference that points to a transient object, another key/value pair is added to the object • For each owned referenceset that points to a transient object, the same approach is taken, except that the value is an array ([]) • Manual serialization process by use of serializeObjectToJson java action.
  • 32. By Acellam Guy @mistaguy JSON Desrialization • an be triggered manually by calling deserializeJsonToObject • Converts the json from the consumer into a mendix transient object • key/value pair for primitive attribute in transient object • If the primitive is of type string, but the member with the same name in the transient object is a reference, the process assumes that the string value represents an url. • If the member in the target object is a reference, and the value is a JSON object, a new object of the child type of the reference is instantiated • If target is reference set and JSON is array then reference set is created
  • 34. By Acellam Guy @mistaguy Assignment • Consume the twitter rest API and show the recent tweets for your profile
  • 35. By Acellam Guy @mistaguy References • http://www.drdobbs.com/web-development/restful-web-services-a- tutorial/240169069 • https://github.com/mendix/RestServices

Editor's Notes

  1. REST has become the default for most Web and mobile apps, it's imperative to have the basics at your fingertips. Every major development language now includes frameworks for building RESTful Web services Almost every RESTful service uses HTTP as its underlying protocol. In this article
  2. Use plural nouns for naming your resources. Avoid using spaces as they create confusion. Use an _ (underscore) or – (hyphen) instead. A URI is case insensitive. I use camel case in my URIs for better clarity. You can use all lower-case URIs. You can have your own conventions, but stay consistent throughout the service. Make sure your clients are aware of this convention. It becomes easier for your clients to construct the URIs programmatically if they are aware of the resource hierarchy and the URI convention you follow. A cool URI never changes; so give some thought before deciding on the URIs for your service. If you need to change the location of a resource, do not discard the old URI. If a request comes for the old URI, use status code 300 and redirect the client to the new location. Avoid verbs for your resource names until your resource is actually an operation or a process. Verbs are more suitable for the names of operations. For example, a RESTful service should not have the URIs http://MyService/FetcthPerson/1 orhttp://MyService/DeletePerson?id=1.
  3. so that your internal data structure is not directly published to the outside. This allows for better maintainability and it guarantees that you can pre- or post-process your data when required.
  4. It will search for the first source object in your database which key value equals the identifier. If found, this object will be converted by thePublish Microflow into a view object. This view object will be serialized to JSON (or HTML or XML) and returned to the consumer.