โ† Ruby on Rails learning path
Ruby on Rails ยท Module 8 of 10

APIs and JSON

Rails can serve JSON APIs for mobile and React apps.

๐Ÿ“– Key ideas

  1. rails new api --api builds a lean API-only app.
  2. render json: @product returns JSON.
  3. Jbuilder or serializers shape the JSON output.
  4. Use HTTP status codes: 200, 201 created, 404, 422 unprocessable.
  5. Token auth (e.g. JWT or API keys) replaces cookies for mobile clients.
๐Ÿ’ก Real-life example: Like a canteen that also delivers: the same kitchen serves plates in the hall and packed boxes to other buildings.
--apiCreates an API-only Rails app
render json:Return JSON from an action
422Status for validation errors
JbuilderTemplates that build JSON