Skip to content

Support for invoking Operations (Actions/Functions) #5

@PandaWhisperer

Description

@PandaWhisperer

Overview

OData supports the notion of Operations: Actions or Functions that can be invoked in order to retrieve data or make modifications on the service.

  • Functions are considered in the "pure" sense (i.e. the may not have side effects, only return data).
  • Actions can have side effects, and may also return data (i.e. they are procedures).

Both actions and functions may be bound to a resource, effectively making them similar to methods in the OOP sense. For instance, if I have a Customer resource, I may have a bound function called MostRecentOrder that is invoked like so:

POST http://host/service/Customers(6)/SampleModel.MostRecentOrder()

On the other hand, an unbound function lives on the service root level directly:

POST http://host/service/EmployeesByManager(ManagerID=3)

Implementation

The above discussion implies that it must be possible to invoke functions on both the OData4::Service instance as well as on individual OData4::Entity instances.

I'm thinking there should be a single method named call(name, ...) or invoke(name, ...) (so as not to be confused with Ruby's built-in Object#send) on both the Service and Entity classes that accepts a function/action name as its first parameter and optional spread args or an options hash for its parameters.

The above examples could then be performed like so:

# Bound function
service['Customers'][6].invoke('MostRecentOrder')

# Unbound function
service.invoke('EmployeesByManager', 'ManagerID' => 3)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions