If using new Rails app BOTH as an API and as a classical MVP app, how is DRY token authentication and versioning of the API accomplished?

Viewed 66

With Rails 6.1 I hope to build a new app whose primary purpose is to supply a versioned API for a Vue.js front end, and mobile apps, but which also needs the classic Rails MVC views available as a web app (mainly for the group managers, as opposed to individual consumers using the consumer Vue front end).

I know creating a classic MVC Rails app allows the controller to respond_to json format, which is ok out of the box for a simple, unversioned API.

But what is a DRY approach to add the following to the classic MVC Rails app:

  • a separate token-based authentication layer for incoming API calls (vs whatever is used for the web app, probably Devise)? No sure where that if-api-use-token-not-devise switch gets handled?
  • namespacing/versioning the API, ideally DRY-ly sharing the same namespaced controller between web & API? Or to put it another way, after creating an new Version-2 of the API how does one configure the Rails web app to use the Version-2 API (while leaving the V1 API active for for users of older front ends)
0 Answers
Related