Just thinking about the structure of our API, with a view to getting everyone on the same page as we make changes to it in future.
Connected to:
- Standalone websites plugged on public instances
- Towards a microservice architecture?
- Embeddable shopfronts
- Interoperability
Where we are now
For the uninitiated, the OFN has a few different “APIs”:
1. Spree’s existing API
- Traditional generic RESTful API
- Quite well structured
- Authentication using API keys
- Designed for external use
- Hasn’t been extended much with OFN functionality
- Views rendered using RABL
2. The OFN’s back-end API
- Designed for internal use
- Authenticates using Rails session
- Mostly RESTful
- Very messy at the controller level - API logic and actions are mixed up with non-API logic and actions in Admin controllers
- Quite a few good conventions/patterns
- Used on most Admin pages, broad scope
- Views rendered using ActiveModelSerializers
3. The OFN’s front-end “API”
- Not an API
- Designed for internal use
- Authentication using Rails session
- Focussed on supporting specific features
- Mainly used on the shop page, very limited in scope
- Not particularly RESTful
- As a side note, a lot of the data in the OFN front-end is rendered using ActiveModelSerializers, but rather than being fetched via AJAX it tends to be rendered directly into the DOM as AngularJS services on page load.
So what?
I suppose the question is - where do we want to get to. Do we need a road map?
If we’re starting to think about external interfaces more seriously, so we extend Spree’s existing API, or do we start fresh?
Should we be separating out all of our JSON/AJAX focussed API actions and logic into separate controller hierarchy?
Do we drop the idea of “internal use only” and instead re-build everything in a single coherent API that works for both? If so, how do we manage authentication while keeping the API nice and DRY?