Skip to content

Feature Request - Add support for "request state" object to endpoints #458

@dswitzer

Description

@dswitzer

I'd love to see Taffy support the ability to define a "state" object that is passed to each endpoint.

This would be an object you could supply to the Taffy framework via something like the onTaffyRequest() or a new onStateRequest() event in Taffy.

The idea is this object is then automatically passed to each method, but is hidden from the public doc generation. This would allow you to pass in state information, allowing you to avoid using Request and Session scopes (which I was find make unit test more brittle). It also gives you a way to pass in object that would be responsible for things such as authentication, permission checking, etc.

The workaround I'm using today is I use the onTaffyRequest() to inject into the requestArguments scope our state object. However, to make sure it does not show up in the OpenAPI docs I've had to customize the Taffy internal OpenAPI to remove the argument from showing up, which feels hacky.

Ideally Taffy's framework would expose a property to define the argument name our state object gets embedded into. Maybe something like:

variables.framework = {
  stateRequestArgument: "RestRequest"
};

// maybe it gets the same arguments as "onTaffyRequest"
function onStateRequest(string verb, string cfc, struct requestArguments, string mimeExt, struct headers, struct methodMetadata, string matchedURI){
  return new StateComponent(user="x", roles="y", whatever=true);
}

In a nutshell, every Taffy component method would receive the "RestRequest" as a named argument (or whatever the value of stateRequestArgument was).

When generating the OpenAPI documentation, this method would be hidden from the docs (since it's an internal object). You could then use this component as a REST helper for whatever type of functionality you need to wire up.

Yes, you could just have your REST methods use things like the Session and Request scope, but passing in an object has always felt better to me for unit tests. Also, not everyone using the Session scope for user authentication (we don't).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions