Skip to content

TypeScript Types + API Client #9

@calebyhan

Description

@calebyhan

Motivation

A typed API client prevents integration bugs and gives all frontend devs autocomplete and type safety when fetching data. Defining types now (mirroring the backend DTOs) means frontend and backend development can proceed in parallel.

Deliverables

  • Create src/types/index.ts (or split by domain) with TypeScript interfaces for all public DTOs:
    • Senator, CommitteeAssignment, Committee, Leadership, News, Legislation, LegislationAction, CalendarEvent, CarouselSlide, FinanceHearingConfig, FinanceHearingDate, Staff, District, BudgetData, StaticPage
  • Create src/types/api.ts for pagination wrapper: PaginatedResponse<T> { items: T[], total: number, page: number, limit: number }
  • Build typed API client in src/lib/api.ts with:
    • Configurable base URL from NEXT_PUBLIC_API_URL env var
    • getNews(page?, limit?)PaginatedResponse<News>
    • getNewsById(id)News
    • getSenators(params?)Senator[]
    • getSenatorById(id)Senator
    • getLeadership(session?)Leadership[]
    • getCommittees()Committee[]
    • getCommitteeById(id)Committee
    • getLegislation(params?)PaginatedResponse<Legislation>
    • getLegislationById(id)Legislation
    • getRecentLegislation(limit?, type?)Legislation[]
    • getEvents(params?)CalendarEvent[]
    • getCarousel()CarouselSlide[]
    • getFinanceHearings()FinanceHearingConfig
    • getStaff()Staff[]
    • getDistricts()District[]
    • getBudget(fiscalYear?)BudgetData[]
    • getStaticPage(slug)StaticPage
  • All functions should handle errors consistently (throw or return error type)
  • Verify the module compiles with npx tsc --noEmit

Important Notes

  • No dependencies — can be built in parallel with FE-1
  • Use fetch (not axios) to keep dependencies minimal
  • The base URL defaults to http://localhost:8000 for local dev
  • Do NOT add admin/mutation API functions yet — those come with admin dashboard tickets
  • BudgetData.children is recursive (children: BudgetData[])

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions