With the introduction of rails API only mode, there is a wealth of documentation on how to create API only applications. There is also a wealth of information on how to create regular rails applications. But what if you want to do both? What if you want a web application and APIs for native mobile applications in the same code base? So far it’s not clear to me what the rails way of doing this is, if there is a rails way to do it, or if the consensus is that you shouldn’t do it that way.
I know that rails controllers respond to json out of the box, so it is possible to get the data that would normally be displayed by the view via a call to the route with
.json appended. But that doesn’t solve the problem of how you would authenticate the mobile application/mobile user alongside web users. I’ve found a few resources that provide workarounds for the token problem:
What I would like to see is official support/documentation for running a traditional web application with HTML views (and cookie/session based authentication) alongside an API that is used by native mobile applications (using tokens or other mobile friendly authentication methods).
This kinda feels like it’s related to rolling authentication into rails core. Maybe it will be easier to do this if authentication was part of rails core. But some documentation would still go a long way in helping someone who is doing this for the first time.