프로젝트 와이어 프레임을 통한 API 간단 설계

ssomae·2024년 9월 26일

DevCourse

목록 보기
22/29
post-thumbnail

프로젝트 2 & 3 설계

API 설계 문서

1. 도서 관련 API

1.1 도서 목록 조회 API

  • Endpoint: GET /books
  • Parameters:
    • keyword: 검색 키워드
    • category: 카테고리 필터
    • page: 페이지 번호
    • limit: 페이지 당 도서 수
  • Response:
    {
      "total_count": 100,
      "books": [
        {
          "id": 1,
          "title": "Book Title",
          "author": "Author Name",
          "summary": "Short description of the book",
          "price": 12000,
          "like_count": 50,
          "image_url": "<https://example.com/image.jpg>"
        }
      ],
      "pagination": {
        "current_page": 1,
        "total_pages": 10
      }
    }
    

1.2 도서 상세 조회 API

  • Endpoint: GET /books/:id
  • Response:
    {
      "id": 1,
      "title": "Book Title",
      "category": "Fiction",
      "author": "Author Name",
      "isbn": "123-456-789",
      "pages": 300,
      "summary": "Detailed description of the book",
      "price": 12000,
      "like_count": 50,
      "images": ["<https://example.com/image1.jpg>", "<https://example.com/image2.jpg>"],
      "is_liked": true
    }
    

2. 사용자 관련 API

2.1 회원가입 API

  • Endpoint: POST /auth/signup
  • Request:
    {
      "email": "user@example.com",
      "password": "password123"
    }
    
  • Response: 201 Created

2.2 로그인 API

  • Endpoint: POST /auth/login
  • Request:
    {
      "email": "user@example.com",
      "password": "password123"
    }
    
  • Response:
    {
      "token": "access-token",
      "refresh_token": "refresh-token"
    }
    

3. 주문 관련 API

3.1 장바구니 조회 API

  • Endpoint: GET /cart
  • Response:
    {
      "items": [
        {
          "id": 1,
          "title": "Book Title",
          "price": 12000,
          "quantity": 1
        }
      ],
      "total_price": 12000
    }
    

3.2 주문 생성 API

  • Endpoint: POST /orders
  • Request:
    {
      "cart_items": [1, 2, 3],
      "shipping_address": "123 Main St",
      "recipient_name": "John Doe",
      "phone": "010-1234-5678",
      "total_price": 36000
    }
    
  • Response: 201 Created

4. 추가 구현 사항

  • 패키지 구조: Router, Controller 구조 필수. 선택적으로 Service, Model 분리 가능.
  • JWT 기반 인증: jsonwebtoken 라이브러리를 사용한 Access Token, Refresh Token 방식.
  • 예외 처리: 유효성 검사 및 예외 처리 구현.
  • 환경변수 관리: dotenv를 통해 환경변수 관리(DB 정보, JWT 시크릿 등).
  • 유효성 검사: 각 요청의 파라미터 유효성 검사.

5. 선택 구현 사항

  • 랜덤 데이터 API 활용: ISBN 샘플 데이터 생성.
  • nodemon: 개발 환경에서 자동 리로드 기능 지원.
profile
성장해나갈 개발자

0개의 댓글