Rubens Silva · Oct 13, 2017 2m read

Frontier: An abstraction layer for rapid REST development - Part 4 - Sharing data across router methods

Hello again and welcome to the next tutorial on this series: Part 4 - Sharing data across router methods.  Here we are going to learn how to share a object containing data that is available for read across every router methods.

You're required to complete at least the Part 1 before entering this one. Still, this is supposed to be a really short tutorial, since there isn't much to be said about data sharing.

  1. Core concepts
    • Getting started
    • Creating a simple request
    • Query parameters
    • Aliasing query parameters
    • Changing output format
    • Rest query parameters
    • Inferring object instances
    • Using literal notation
    • Seamlessly mixing instances with literals
    • Returning streams
  2. Handling payloads
    • ​​How it works
    • Making it useful
    • Unmarshalling payloads into instances
    • Using the unmarshaller to EDIT an existing object
  3. Using the SQL API
    • ​​Creating a simple dynamic query
    • Overwriting the default container property
    • Using cached queries
    • Passing parameters to queries
  4. Sharing data across router methods
  5. Forcing API errors
  6. Managing errors with Reporters

4. Sharing data across router methods

Straight to the point, simply define a method called:

ClassMethod OnDataSet(data As %DynamicObject) As %Status
  set data.Message = "This 'Message' is shared between all methods."
  return $$$OK

The data object is where you put whatever you need available for every method. This way all methods can access the data you provided by using:

ClassMethod GetMessage() As %DynamicObject
  return %frontier.Data

 This is the method that you would bind to some route. Like this one:

<Route Url="/shared_data" Method="GET" Call="GetMessage"/>

So now when you request a method using that Data, you'll notice that it can actually access it's contents.


This concludes the part 4. Next time, we're going to see how to force and handle application errors.

Keep in touch!

0 398
Discussion (0)1
Log in or sign up to continue