Class: Api::SessionsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/api/sessions_controller.rb

Overview

REST endpoint for session management. The TUI client uses this to obtain a session ID before subscribing to the WebSocket channel.

Instance Method Summary collapse

Instance Method Details

#createJSON

Creates a new conversation session.

POST /api/sessions

Returns:

  • (JSON)

    { id: Integer }



20
21
22
23
# File 'app/controllers/api/sessions_controller.rb', line 20

def create
  session = Session.create!
  render json: {id: session.id}, status: :created
end

#currentJSON

Returns the most recent session or creates one if none exist.

GET /api/sessions/current

Returns:

  • (JSON)

    { id: Integer }



11
12
13
14
# File 'app/controllers/api/sessions_controller.rb', line 11

def current
  session = Session.last || Session.create!
  render json: {id: session.id}
end