openapi: 3.0.3
info:
  title: DomainDetails API
  description: |
    Domain information lookup API providing WHOIS/RDAP data, marketplace search, and pricing information.

    ## Features
    - **RDAP Lookup**: Get structured RDAP data with registry and registrar merge, falls back to WHOIS
    - **WHOIS Lookup**: Get parsed and raw WHOIS data for any domain
    - **DNS Lookup**: Query DNS records using Cloudflare DNS-over-HTTPS
    - **SSL Check**: Check SSL/TLS certificate status for any domain
    - **Wayback History**: Get Internet Archive snapshots for a domain
    - **Pricing Check**: Check domain registration and renewal pricing

    ## Rate Limits
    - 100 requests/minute
  version: 1.0.0
  contact:
    name: DomainDetails
    url: https://domaindetails.com

servers:
  - url: https://api.domaindetails.com
    description: Production server

tags:
  - name: RDAP
    description: RDAP lookup with registry/registrar merge
  - name: WHOIS
    description: Domain WHOIS lookup endpoints
  - name: Pricing
    description: Domain pricing endpoints
  - name: Tools
    description: Domain tools (DNS, SSL, Wayback)
  - name: Health
    description: API health check

paths:
  /api/rdap:
    get:
      tags:
        - RDAP
      summary: RDAP Lookup
      description: |
        Retrieve domain information using RDAP protocol. Automatically merges data from both registry and registrar RDAP servers when available.

        Falls back to WHOIS if RDAP is not available for the TLD.

        Returns standardized data structure regardless of the underlying protocol used.
      operationId: rdapLookup
      parameters:
        - name: domain
          in: query
          required: true
          description: The domain name to look up (e.g., example.com)
          schema:
            type: string
            example: google.com
      responses:
        '200':
          description: Successful RDAP lookup
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RdapResponse'
              examples:
                registered:
                  summary: Registered domain
                  value:
                    domain: google.com
                    available: false
                    standardizedData:
                      - key: Domain
                        value: google.com
                      - key: Type
                        value: domain
                      - key: Status
                        value: 'clientDeleteProhibited, clientTransferProhibited, clientUpdateProhibited, serverDeleteProhibited, serverTransferProhibited, serverUpdateProhibited'
                      - key: Registrar
                        value: MarkMonitor Inc.
                      - key: Creation Date
                        value: '1997-09-15T04:00:00Z'
                      - key: Expiration Date
                        value: '2028-09-14T04:00:00Z'
                      - key: DNSSEC
                        value: DNSSEC off
                      - key: Nameservers
                        value: 'ns1.google.com, ns2.google.com, ns3.google.com, ns4.google.com'
                    rawData: '{"objectClassName":"domain","handle":"2138514_DOMAIN_COM-VRSN",...}'
                    dataSources:
                      - type: RDAP
                        url: 'https://rdap.verisign.com/com/v1/domain/google.com'
                        source: Registry
                available:
                  summary: Available domain
                  value:
                    domain: thisdomain-is-available-12345.com
                    available: true
                    message: This domain appears to be available for registration.
                    rawData: 'No match for "THISDOMAIN-IS-AVAILABLE-12345.COM".'
                    dataSources:
                      - type: WHOIS
                        server: whois.verisign-grs.com
        '400':
          description: Bad request - domain parameter missing or TLD not supported
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                missing:
                  summary: Missing domain parameter
                  value:
                    error: Domain parameter is required
                unsupported:
                  summary: TLD not supported
                  value:
                    error: TLD not supported
                    message: 'Domain lookup not supported for TLD: .xyz. This TLD either doesn''t have a WHOIS server or is not supported yet.'
        '500':
          description: Server error during lookup
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'

  /api/whois:
    get:
      tags:
        - WHOIS
      summary: WHOIS Lookup (Query Parameter)
      description: |
        Retrieve WHOIS/RDAP data for a domain. Returns both parsed structured data and raw WHOIS output.

        The API automatically uses RDAP when available for the TLD, falling back to WHOIS otherwise.
      operationId: whoisLookupQuery
      parameters:
        - name: domain
          in: query
          required: true
          description: The domain name to look up (e.g., example.com)
          schema:
            type: string
            example: google.com
      responses:
        '200':
          description: Successful WHOIS lookup
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WhoisResponse'
              example:
                parsedData:
                  Domain Name: google.com
                  Registry Domain ID: '2138514_DOMAIN_COM-VRSN'
                  Registrar: MarkMonitor Inc.
                  Registrar IANA ID: '292'
                  Creation Date: '1997-09-15T04:00:00Z'
                  Expiration Date: '2028-09-14T04:00:00Z'
                  Name Server: ns1.google.com
                rawData: 'Domain Name: GOOGLE.COM\nRegistry Domain ID: 2138514_DOMAIN_COM-VRSN\n...'
        '400':
          description: Bad request - domain parameter missing or invalid
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error: Domain parameter is required
        '404':
          description: WHOIS server not found for this TLD
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error: WHOIS server not found for this TLD
        '500':
          description: Server error during WHOIS lookup
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'

  /api/whois/{domain}:
    get:
      tags:
        - WHOIS
      summary: WHOIS Lookup (Path Parameter)
      description: |
        Retrieve WHOIS/RDAP data for a domain using path parameter.

        Alternative to the query parameter endpoint for cleaner URLs.
      operationId: whoisLookupPath
      parameters:
        - name: domain
          in: path
          required: true
          description: The domain name to look up (e.g., example.com)
          schema:
            type: string
            example: google.com
      responses:
        '200':
          description: Successful WHOIS lookup
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WhoisResponse'
        '400':
          description: Bad request - domain parameter missing or invalid
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: WHOIS server not found for this TLD
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Server error during WHOIS lookup
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'

  /api/pricing/check:
    get:
      tags:
        - Pricing
      summary: Check Domain Pricing
      description: |
        Check domain registration and renewal pricing across registrars.

        Returns availability status and pricing information including whether the domain is considered premium.

      operationId: pricingCheck
      parameters:
        - name: domain
          in: query
          required: true
          description: The domain name to check pricing for
          schema:
            type: string
            example: example.com
      responses:
        '200':
          description: Domain pricing information
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PricingResponse'
              example:
                available: true
                pricing:
                  registration: 12.99
                  renewal: 14.99
                  isPremium: false
                  currency: USD
                provider: namecheap
        '400':
          description: Bad request - domain parameter missing
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: Rate limit exceeded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Server error during pricing check
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'

  /api/dns:
    get:
      tags:
        - Tools
      summary: DNS Lookup
      description: |
        Query DNS records for a domain using Cloudflare DNS-over-HTTPS.

        Supports common record types: A, AAAA, CNAME, MX, NS, TXT, SOA, CAA, PTR.
      operationId: dnsLookup
      parameters:
        - name: domain
          in: query
          required: true
          description: The domain name to look up
          schema:
            type: string
            example: google.com
        - name: type
          in: query
          required: false
          description: "DNS record type (default: A)"
          schema:
            type: string
            enum: [A, AAAA, CNAME, MX, NS, TXT, SOA, CAA, PTR]
            default: A
      responses:
        '200':
          description: DNS lookup results
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DnsResponse'
              example:
                domain: google.com
                type: A
                status: success
                statusCode: 0
                answers:
                  - name: google.com
                    type: 1
                    TTL: 300
                    data: 142.250.185.206
                queriedAt: '2025-01-15T10:30:00Z'
        '400':
          description: Bad request - domain parameter missing or invalid record type
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Server error during DNS lookup
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'

  /api/ssl:
    get:
      tags:
        - Tools
      summary: SSL Certificate Check
      description: |
        Check SSL/TLS certificate status for a domain.

        Returns information about HTTPS availability, HSTS configuration, and basic certificate details.
      operationId: sslCheck
      parameters:
        - name: domain
          in: query
          required: true
          description: The domain name to check
          schema:
            type: string
            example: google.com
      responses:
        '200':
          description: SSL check results
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SslResponse'
              examples:
                secure:
                  summary: Domain with valid SSL
                  value:
                    success: true
                    domain: google.com
                    hasSSL: true
                    isSecure: true
                    httpsAvailable: true
                    hsts: true
                    hstsMaxAge: 31536000
                    protocol: TLS
                    checkedAt: '2025-01-15T10:30:00Z'
                insecure:
                  summary: Domain without SSL
                  value:
                    success: false
                    domain: example.com
                    hasSSL: false
                    httpsAvailable: false
                    httpAvailable: true
                    error: SSL connection failed
                    errorType: ssl_error
                    checkedAt: '2025-01-15T10:30:00Z'
        '400':
          description: Bad request - domain parameter missing
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Server error during SSL check
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'

  /api/wayback:
    get:
      tags:
        - Tools
      summary: Wayback Machine History
      description: |
        Get Internet Archive Wayback Machine snapshots for a domain.

        Returns up to 1000 unique snapshots (deduplicated by content digest).
      operationId: waybackHistory
      parameters:
        - name: domain
          in: query
          required: true
          description: The domain name to look up
          schema:
            type: string
            example: google.com
      responses:
        '200':
          description: Wayback Machine snapshots
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WaybackResponse'
              example:
                - ['timestamp', 'statuscode', 'mimetype', 'digest']
                - ['20050101120000', '200', 'text/html', 'ABC123...']
                - ['20100615080000', '200', 'text/html', 'DEF456...']
        '400':
          description: Bad request - domain parameter missing
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Server error during Wayback lookup
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'

  /health:
    get:
      tags:
        - Health
      summary: Health Check
      description: Check if the API server is running and healthy.
      operationId: healthCheck
      responses:
        '200':
          description: Server is healthy
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: ok

components:
  schemas:
    RdapResponse:
      type: object
      properties:
        domain:
          type: string
          description: The queried domain name
        available:
          type: boolean
          description: Whether the domain is available for registration
        message:
          type: string
          description: Message when domain is available
        standardizedData:
          type: array
          description: Standardized domain data in key-value format
          items:
            type: object
            properties:
              key:
                type: string
                description: Field name (e.g., Domain, Registrar, Creation Date)
              value:
                description: Field value (string or object)
        rawData:
          type: string
          description: Raw RDAP JSON response or WHOIS text
        dataSources:
          type: array
          description: Sources used for the lookup
          items:
            type: object
            properties:
              type:
                type: string
                description: Protocol used (RDAP or WHOIS)
              url:
                type: string
                description: RDAP URL if applicable
              source:
                type: string
                description: Source type (Registry, Registrar)
              server:
                type: string
                description: WHOIS server if applicable

    WhoisResponse:
      type: object
      properties:
        parsedData:
          type: object
          description: Structured WHOIS data parsed into key-value pairs
          additionalProperties:
            type: string
        rawData:
          type: string
          description: Raw WHOIS response text

    DnsResponse:
      type: object
      properties:
        domain:
          type: string
          description: The queried domain name
        type:
          type: string
          description: DNS record type queried
        status:
          type: string
          enum: [success, error]
          description: Lookup status
        statusCode:
          type: integer
          description: DNS response code (0 = success)
        answers:
          type: array
          description: DNS answer records
          items:
            type: object
            properties:
              name:
                type: string
              type:
                type: integer
              TTL:
                type: integer
              data:
                type: string
        authority:
          type: array
          description: Authority records
          items:
            type: object
        truncated:
          type: boolean
        recursionDesired:
          type: boolean
        recursionAvailable:
          type: boolean
        authenticatedData:
          type: boolean
        checkingDisabled:
          type: boolean
        queriedAt:
          type: string
          format: date-time

    SslResponse:
      type: object
      properties:
        success:
          type: boolean
          description: Whether SSL check succeeded
        domain:
          type: string
          description: The checked domain
        hasSSL:
          type: boolean
          description: Whether domain has SSL certificate
        isSecure:
          type: boolean
          description: Whether connection is secure
        httpsAvailable:
          type: boolean
          description: Whether HTTPS is available
        httpAvailable:
          type: boolean
          description: Whether HTTP is available (only on failure)
        redirectsToHTTPS:
          type: boolean
          description: Whether HTTP redirects to HTTPS
        server:
          type: string
          description: Server header value
        hsts:
          type: boolean
          description: Whether HSTS is enabled
        hstsMaxAge:
          type: integer
          description: HSTS max-age in seconds
        protocol:
          type: string
          description: TLS protocol used
        error:
          type: string
          description: Error message if check failed
        errorType:
          type: string
          enum: [timeout, ssl_error, connection_error]
          description: Type of error if check failed
        checkedAt:
          type: string
          format: date-time

    WaybackResponse:
      type: array
      description: Array of snapshots. First item is header row, rest are data rows.
      items:
        type: array
        items:
          type: string
        description: '[timestamp, statuscode, mimetype, digest]'

    PricingResponse:
      type: object
      properties:
        available:
          type: boolean
          description: Whether the domain is available for registration
        pricing:
          type: object
          properties:
            registration:
              type: number
              description: Registration price
            renewal:
              type: number
              description: Renewal price
            isPremium:
              type: boolean
              description: Whether this is a premium domain
            currency:
              type: string
              description: Price currency (e.g., USD)
        provider:
          type: string
          description: Registrar providing the pricing

    Error:
      type: object
      required:
        - error
      properties:
        error:
          type: string
          description: Error message
        message:
          type: string
          description: Additional error details
        retryAfter:
          type: integer
          description: Seconds to wait before retrying (for rate limits)
