take a small rest
play

Take a small REST Simple approaches for REST in smalltalk Norbert - PowerPoint PPT Presentation

Take a small REST Simple approaches for REST in smalltalk Norbert Hartl 2denker What we do... ...at 2denker mobile applications backend services for mobile applications backend services for b2b Why REST? there are RPC-style services (SOAP


  1. Take a small REST Simple approaches for REST in smalltalk Norbert Hartl 2denker

  2. What we do... ...at 2denker mobile applications backend services for mobile applications backend services for b2b

  3. Why REST? there are RPC-style services (SOAP , XML-RPC,...)

  4. Why REST? there are RPC-style services (SOAP , XML-RPC,...) REST is data-centric

  5. Why REST? there are RPC-style services (SOAP , XML-RPC,...) REST is data-centric REST/HTTP has meta data

  6. Why REST? there are RPC-style services (SOAP , XML-RPC,...) REST is data-centric REST/HTTP has meta data REST is about identity

  7. Smalltalk tools to do REST Magritte Magritte-XMLBinding Magritte-JSON Seaside-REST

  8. serialization/materialization using magritte meta tool support model with meta information validation of model using meta information conversion into/from formats with meta info

  9. Example class Person fullName emailAddress

  10. model with meta information Person>>#fullNameDescription <magritteDescription> ^ MAStringDescription new accessor: #fullName; label: 'full name'; beRequired; priority: 100; yourself

  11. model with meta information (using pragma to add a description) Person>>#fullNameDescription < magritteDescription > ^ MAStringDescription new accessor: #fullName; label: 'full name'; beRequired; priority: 100; yourself

  12. model with meta information (adding type information) Person>>#fullNameDescription <magritteDescription> ^ MAStringDescription new accessor: #fullName; label: 'full name'; beRequired; priority: 100; yourself

  13. model with meta information (specifying value store/retrieve operation) Person>>#fullNameDescription <magritteDescription> ^ MAStringDescription new accessor: #fullName ; label: 'full name'; beRequired; priority: 100; yourself

  14. validation using meta info (magritte) Person>>#emailAddressDescription <magritteDescription> ^ MAStringDescription new accessor: #emailAddress; label: 'email address'; addCondition: [:val| val includes: $@ ] labelled: 'address must contain @'; beRequired; priority: 200; yourself

  15. validation using meta info (magritte) Person>>#emailAddressDescription <magritteDescription> ^ MAStringDescription new accessor: #emailAddress; label: 'email address'; addCondition: [:val| val includes: $@ ] labelled: 'address must contain @'; beRequired; priority: 200; yourself

  16. validation using meta info (magritte) Person>>#emailAddressDescription <magritteDescription> ^ MAStringDescription new accessor: #emailAddress; label: 'email address'; addCondition: [:val| val includes: $@ ] labelled: 'address must contain @'; beRequired; priority: 200; yourself

  17. adding conversion info (for Magritte-XMLBinding) fullNameXmlDescription: aDescription <magritteDescription: #fullNameDescription> ^ aDescription xmlElementName: 'fullname' emailAddressXmlDescription: aDescription <magritteDescription: #emailAddressDescription> ^ aDescription xmlAttributeName: 'email'

  18. conversion into/from format p := Person new. p fullName: 'John Doe'; emailAddress: 'john@doe.it'. p magritteDescription toXml: p <Person email="john@doe.it"> <fullname>John Doe</fullname> </Person>

  19. REST call flow message routing and parameter handling content type selection serializiation/materialization to/from network data

  20. message routing time <get> <path: '/time'> self requestContext response status: 200; nextPutAll: Time now greaseString; respond

  21. message routing (matching HTTP verb) time <get> <path: '/time'> self requestContext response status: 200; nextPutAll: Time now greaseString; respond

  22. message routing (matching path/parameters) time <get> <path: '/time'> self requestContext response status: 200; nextPutAll: Time now greaseString; respond

  23. content type xml getPersonXml: aString <get> <path: '/person/{1}'> <produces: 'application/xml'> self requestContext response status: 200; nextPutAll: ( self description toXml: (self personWithId: aString)); respond

  24. content type xml (placeholder in url become method paramter) getPersonXml: aString <get> <path: '/person/ {1} '> <produces: 'application/xml'> self requestContext response status: 200; nextPutAll: ( self description toXml: (self personWithId: aString)); respond

  25. content type xml (content type selection based on Accept header) getPersonXml: aString <get> <path: '/person/{1}'> <produces: 'application/xml'> self requestContext response status: 200; nextPutAll: ( self description toXml: (self personWithId: aString)); respond

  26. content type json getPersonJson: aString <get> <path: '/person/{1}'> <produces: 'application/json'> self requestContext response status: 200; nextPutAll: (String streamContents: [:stream| (self personWithId: aString) jsonOn: stream]); respond

  27. example post addPersonFromJson <post> <path: '/person'> <consumes: 'application/json'> self addPersonUsing: [ self materializeFromJson ]

  28. example post (content type selection based on Content-Type header) addPersonFromJson <post> <path: '/person'> <consumes: 'application/json'> self addPersonUsing: [ self materializeFromJson ]

  29. Demo

  30. Thank you! Questions?

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend