# Class SessionController

java.lang.Object
com.google.adk.web.controller.SessionController

@RestController public class SessionController extends Object
Controller handling session-related API endpoints.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `SessionController(BaseSessionService sessionService)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Session`
  `createSession(String appName, String userId, SessionRequest body)`
  Creates a new session where the ID is generated by the service.
  `Session`
  `createSessionWithId(String appName, String userId, String sessionId, SessionRequest body)`
  Creates a new session with a specific ID provided by the client.
  `org.springframework.http.ResponseEntity<Void>`
  `deleteSession(String appName, String userId, String sessionId)`
  Deletes a specific session.
  `Session`
  `getSession(String appName, String userId, String sessionId)`
  Retrieves a specific session by its ID.
  `List<Session>`
  `listSessions(String appName, String userId)`
  Lists all non-evaluation sessions for a given app and user.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### SessionController

    @Autowired public SessionController(BaseSessionService sessionService)

- ## Method Details

  - ### getSession

    @GetMapping("/apps/{appName}/users/{userId}/sessions/{sessionId}") public Session getSession(@PathVariable String appName, @PathVariable String userId, @PathVariable String sessionId)
    Retrieves a specific session by its ID.
    Parameters:
      `appName` - The application name.
      `userId` - The user ID.
      `sessionId` - The session ID.
    Returns:
      The requested Session object.
    Throws:
      `org.springframework.web.server.ResponseStatusException` - if the session is not found.

  - ### listSessions

    @GetMapping("/apps/{appName}/users/{userId}/sessions") public List<Session> listSessions(@PathVariable String appName, @PathVariable String userId)
    Lists all non-evaluation sessions for a given app and user.
    Parameters:
      `appName` - The name of the application.
      `userId` - The ID of the user.
    Returns:
      A list of sessions, excluding those used for evaluation.

  - ### createSessionWithId

    @PostMapping("/apps/{appName}/users/{userId}/sessions/{sessionId}") public Session createSessionWithId(@PathVariable String appName, @PathVariable String userId, @PathVariable String sessionId, @RequestBody(required=false) SessionRequest body)
    Creates a new session with a specific ID provided by the client.
    Parameters:
      `appName` - The application name.
      `userId` - The user ID.
      `sessionId` - The desired session ID.
    Returns:
      The newly created Session object.
    Throws:
      `org.springframework.web.server.ResponseStatusException` - if a session with the given ID already exists (BAD_REQUEST) or if creation fails (INTERNAL_SERVER_ERROR).

  - ### createSession

    @PostMapping("/apps/{appName}/users/{userId}/sessions") public Session createSession(@PathVariable String appName, @PathVariable String userId, @RequestBody(required=false) SessionRequest body)
    Creates a new session where the ID is generated by the service.
    Parameters:
      `appName` - The application name.
      `userId` - The user ID.
    Returns:
      The newly created Session object.
    Throws:
      `org.springframework.web.server.ResponseStatusException` - if creation fails (INTERNAL_SERVER_ERROR).

  - ### deleteSession

    @DeleteMapping("/apps/{appName}/users/{userId}/sessions/{sessionId}") public org.springframework.http.ResponseEntity<Void> deleteSession(@PathVariable String appName, @PathVariable String userId, @PathVariable String sessionId)
    Deletes a specific session.
    Parameters:
      `appName` - The application name.
      `userId` - The user ID.
      `sessionId` - The session ID to delete.
    Returns:
      A ResponseEntity with status NO_CONTENT on success.
    Throws:
      `org.springframework.web.server.ResponseStatusException` - if deletion fails (INTERNAL_SERVER_ERROR).