Apux — A Flux inspired, Aspnet core API

Or otherwise known as, I cant believe its not JSON RPC..

What the Flux?

The general gist of Flux is that its a unidirectional data flow. Now that’s something I’m completely disregarding for our use case. I suppose that makes it very loosely Flux-inspired… but hey what are we as devs without cool sounding patterns?

The basic Flux flow

A-pux for your Flux

So how do we modify this MVC-based data flow pattern for an API? Well lets see what sense we can make from the diagram below.

Our slightly bastardized Flux flow for an API (Apux)

Show me the Action

So what does an action actually look like in our aspnet API? Well first up we have the interface:

Action D-D-Dispatch

Okay, so we can now form a JSON action that looks like something like this:

Can you handle that?

The product dispatcher then finally hands the action to the appropriate action handler for that action. The action handler does some work, calling for example some business logic, or data access, then returns an action result.

Finally, we have a result

Once we have the final action result, we return it as a JSON payload that looks something like this:

Still awake?

Awesome, well then you at least found this mildly interesting.. on a serious note, whilst I really like this pattern, it does have its place. I think its a great replacement for building REST API’s that solely support a single app. As mentioned in the article that inspired this work, I think if you’re exposing a generic API to the world, then REST is still your best bet.

  • We can wrap a transaction scope for db calls around an entire set of actions
  • The frontend can share the string constant definitions of the actions within the API
  • We’ve stopped boxing/unboxing values into URLs/routes and query params between the backend and frontend
  • We can create small, modular, atomic actions, then chain them together when needed
  • API Versioning can be easily done at an action level
  • We’re acting outside the usual aspnet MVC controller pattern, meaning its sometimes difficult to use some of the great baked-in controller features.
  • Because of the above, things like endpoint/action authorisation & authentication become a manual process
  • A slight overhead is added to each call with all the action switching logic

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Dan Harris

full-stack dev, grad advocate, beer enthusiast, organiser heapsgood dev beers, co-organiser frontend dev ADL