JSON-API
This document covers how to create the best structure to create HTTP REST JSON API's
Routes
- Read Routes
- Use
namespaceandscopeto isolate the routes specific to JSON
Controllers
- Create a specific versioned folder in
app/controllers. Example:app/controllers/api/api_controller.rb - Create an
api_controller.rbin the root of the folder containing the others API controllers and make them inherit fromapi_controller.rb. Because the authentication logic should be different (based on headers and not cookies for example). - Create a folder
v1and thenv2inapp/controllers/api/when your API is evolving. - Use version in the URL and inheritance in controller to reuse existing actions
Testing
- You can send raw JSON to API endpoints for integration testing and check the returned JSON.