Skip to content

Add POST /api/chats endpoint#104

Merged
sweetmantech merged 4 commits intotestfrom
sweetmantech/myc-3881-api-rooms-post-chats
Jan 9, 2026
Merged

Add POST /api/chats endpoint#104
sweetmantech merged 4 commits intotestfrom
sweetmantech/myc-3881-api-rooms-post-chats

Conversation

@sweetmantech
Copy link
Contributor

@sweetmantech sweetmantech commented Jan 9, 2026

Summary

  • Add POST /api/chats endpoint for creating new chat rooms
  • Account ID is inferred from the API key (x-api-key header)
  • Optional artistId and chatId parameters
  • chatId is auto-generated if not provided

Files Changed

  • lib/chats/createChatHandler.ts - Handler function
  • app/api/chats/route.ts - API route with OPTIONS and POST handlers

Test plan

  • Test creating a chat with valid API key
  • Test creating a chat with artistId
  • Test creating a chat with custom chatId
  • Test error response with invalid/missing API key

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added a new chat creation API endpoint with CORS support and API key-based authentication for secure chat room creation and management.
  • Documentation

    • Introduced standardized input validation patterns and documentation for validating API request payloads, including error handling guidelines, missing field detection, and consistent JSON response formatting conventions.

✏️ Tip: You can customize this high-level summary in your review settings.

- Add createChatHandler in lib/chats/
- Add POST route at app/api/chats/
- Account ID inferred from API key
- Optional artistId and chatId params
- chatId auto-generated if not provided

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@vercel
Copy link
Contributor

vercel bot commented Jan 9, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
recoup-api Ready Ready Preview Jan 9, 2026 2:57pm

@coderabbitai
Copy link

coderabbitai bot commented Jan 9, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

This pull request introduces a new chat creation API endpoint with comprehensive validation, authentication, and database integration. It includes documentation for standardized input validation patterns, a new route handler with CORS support, utility functions for safe JSON parsing, and Zod-based schema validation.

Changes

Cohort / File(s) Summary
Documentation
CLAUDE.md
Adds Input Validation section documenting standardized Zod-based validation pattern with schema definitions, typed exports, and usage examples
API Route
app/api/chats/route.ts
New route file exporting OPTIONS and POST handlers; OPTIONS returns CORS preflight headers, POST delegates to createChatHandler
Chat Creation Handler
lib/chats/createChatHandler.ts
Server handler for chat creation: authenticates via API key, validates request body, generates or uses provided roomId, inserts record into database, returns JSON response with CORS headers; includes error handling with standardized error payloads
Chat Body Validation
lib/chats/validateCreateChatBody.ts
Zod schema validator for CreateChatBody; returns NextResponse with 400 status and error details on failure, or validated typed data on success
JSON Parsing Utility
lib/networking/safeParseJson.ts
Safe async JSON parser for NextRequest; returns parsed payload on success or empty object on parse failure

Sequence Diagram(s)

sequenceDiagram
    actor Client
    participant Route as app/api/chats/route.ts
    participant Handler as createChatHandler
    participant Validator as validateCreateChatBody
    participant Auth as Auth Service
    participant DB as Database
    
    Client->>Route: POST /api/chats (with body)
    Route->>Handler: forwards request
    Handler->>Handler: parse request JSON
    Handler->>Validator: validate body
    Validator-->>Handler: validated data or error response
    alt validation fails
        Handler-->>Client: 400 response with error details
    else validation succeeds
        Handler->>Auth: authenticate via API key
        Auth-->>Handler: accountId
        Handler->>DB: insert new room record
        DB-->>Handler: success
        Handler-->>Client: 200 response with created chat + CORS headers
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A chat is born with validation's grace,
Zod schemas keep bad data from this place,
CORS headers flow, authentication's tight,
New endpoints dance in the server's light! ✨

✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5354e16 and aeee4dd.

📒 Files selected for processing (5)
  • CLAUDE.md
  • app/api/chats/route.ts
  • lib/chats/createChatHandler.ts
  • lib/chats/validateCreateChatBody.ts
  • lib/networking/safeParseJson.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

- Document validate function pattern using Zod in CLAUDE.md
- Add validateCreateChatBody.ts for POST /api/chats
- Update createChatHandler to use the validate function

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Create safeParseJson helper that returns {} if body is empty/invalid
- Use in createChatHandler so body is not required
- All params are optional, so empty body should work

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@sweetmantech
Copy link
Contributor Author

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Jan 9, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@sweetmantech sweetmantech merged commit dbee139 into test Jan 9, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments