Incremental Rails to SPA Migration with Mock APIs
Table of Contents
- 1. Background
- 2. Scenario
- 2.1. Create a mock Rails application
- 2.2. Scaffold several objects
- 2.3. Document the external POST and GET endpoint
- 2.4. Create initial consumer of mock API
- 2.5. Return JSON rather than HTML
- 2.6. Load mock data
- 2.7. Validate the implementation with cUrl
- 2.8. Create the Swagger documentation
- 2.9. Create the route mocks for the Python
- 3. Links
- 4. Tools
- 5. Related
1. Background
Provide a simple mechanism from creating a base Rails application with an incremental path to migrate to a SPA backing based on a namespace switch to /api.
The goal will be to keep all of the core business logic for persisting data in Rails but gradually move features to the front-end in either Angular or React.
2. Scenario
2.1. Create a mock Rails application
rails new appmigapi
2.4. Create initial consumer of mock API
corrected
Yeoman's CLI binary is =yo=, invoked as =yo <generator>=; there was never a =yeoman new <app>= command, in the 2013+ =yo= era or the earlier (pre-1.0) =yeoman init= era. Confirmed against yeoman.io's own quickstart ("To scaffold a new project, run: =yo webapp=").
yo react-app
2.5. Return JSON rather than HTML
correct
respond_to :json
2.6. Load mock data
correct
group :development, :test do
gem 'faker'
end
3. Links
5. Related
- SPA Setup with Rails: JSON API and Angular – the API the mocks stand in for
- SPA Integration – routing and deployment once the SPA is real
- Design-Driven APIs – contracts first, mocks generated from them