Skip to content

Reference: Services ​

Every HTTP call from the frontend goes through a function in src/services/api.ts. For full signatures, parameters, and JSDoc, see the source file on GitHub.

The shared infrastructure ​

SymbolWhat it does
apiFetchThe single fetch wrapper used by every service. Handles auth cookies, JSON parsing, error wrapping.
buildParamsTurns a record of values into URLSearchParams, skipping undefined values.
ApiErrorThrown by apiFetch on non-2xx responses. Carries the HTTP status and parsed message body.

Auth and account ​

FunctionEndpointPurpose
fetchUser()GET /dashboardReads the current user from the session cookie. 401 = logged out.
logoutUser()POST /api/auth/logoutEnds the server session.
updateUser()PATCH /api/userUpdates display name and email. Returns the full updated user.
deleteAccount()DELETE /api/userPermanently deletes the account and all associated data.

Connected services ​

FunctionEndpointPurpose
fetchConnectedServices()GET /api/connected-servicesLists every streaming service linked to the account.
disconnectService()DELETE /api/connected-services/:providerRemoves one provider link. Caller handles the "last provider" case.

Listening data ​

FunctionEndpointPurpose
fetchTopTracks()GET /api/top-tracksTop tracks for a time range.
fetchTopArtists()GET /api/top-artistsTop artists for a time range.
fetchTopGenres()GET /api/top-genresTop genres for a time range. Default limit 5.
fetchTopSkips()GET /api/top-skipsMost-skipped tracks.
fetchTopReplays()GET /api/top-replaysMost-replayed tracks (back-to-back plays).
fetchPeakHour()GET /api/peak-hourThe hour (0–23) with the highest play count.
fetchMostActiveDay()GET /api/most-active-dayThe single date with the most plays.
fetchTimeListened()GET /api/time-listenedTotal milliseconds listened in the range.
fetchHistory()GET /api/historyPaginated raw plays.
fetchWrapped()GET /api/wrappedSingle payload powering the Wrapped slides.
uploadHistory()POST /uploadMultipart upload of a Spotify export .zip.

Conventions ​

  • Every service returns a Promise<TypedResponse>.
  • timeRange is optional; omitting it defaults the backend to "all time".
  • Pagination follows the Pagination interface in src/types/api.ts.
  • All services throw ApiError on non-2xx and are handled at the hook or component layer, not inside services.

Built for SE_07 — Technical Documentation